HansSchouten / Laravel-Pagebuilder

A drag and drop pagebuilder to manage pages in any Laravel project
https://www.phpagebuilder.com
MIT License
800 stars 184 forks source link

handle a form through the pagebuilder #107

Open estelle-zeuk opened 3 years ago

estelle-zeuk commented 3 years ago

Hello everyone! I've had a contact block in my pagebuilder, and i would like to the user input and send them by mail, but i'm stuck. The controller i've created is not reached.

This is my controller `namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller; use Illuminate\Http\Request;

class ContactController extends Controller { public function contact(Request $request){ $inputs = $request->all(); dd('testons'); try { $email = "essytelle@gmail.com"; //$view = 'landing-page.email'; //dd($inputs['subject']); / \Mail::send($view, compact('inputs'), function ($message) use ($email, $inputs) { $message->to($email, 'Equipe vente')->subject($inputs['subject']); }); /

        return response()->json(['success'=>true,'message'=>'Message envoyé avec succès']);
    } catch (\Exception $e) {
        dd($e);
        return response()->json(['success'=>false, 'message'=>'Une erreur s\'est produite']);
    }
}

}` Need your help please @HansSchouten

HansSchouten commented 3 years ago

Hi, currently the project would match any route and handle the request in the phpagebuilder router to load and construct the right page. So that could be why your Laravel controller is not reached. Although your routes.php file should be matched before the Laravel Pagebuilder's routes.php, so maybe you can check whether that is the case.

Alternatively you could also use a custom Laravel controller to render all pagebuilder pages, see here. In that case you have more control over the routes and the order in which they are matched.

Or you could create a controller.php file in your contact block and handle the form over there.

estelle-zeuk commented 3 years ago

Thank you @HansSchouten I will try it

estelle-zeuk commented 3 years ago

Hi all!!! I tried to send data to my controller, even to a simple php page, but my ajax call is empty with the status ok! I don't understand @HansSchouten

HansSchouten commented 3 years ago

Possibly you are sending the request to an URL that does not exist and the router of PHPageBuilder routes this request to an empty error page. Do you have a page with the route /*, this is a catch all that might handle the request right now.

estelle-zeuk commented 3 years ago

Or you could create a controller.php file in your contact block and handle the form over there. I have done this, but, still, the data are not being sent to my php file @HansSchouten

HansSchouten commented 3 years ago

So if you try using an exit(); in the handleRequest method of the controller you have created, the pages with that block should all react and become empty. If that works you might need to check the link you are using in the request.