简体   繁体   中英

How to pull HTML form details in controller in Laravel 5.4?

I am working on building a form in which I want to populate the fields coming from form (which I have named posting.blade.php)

The controller which I have used for that is:

public function store(Request $request)
{
    $this->validate($request, [
    'name' => 'required',
    'email' => 'required|email',
    'number' => 'required',
    'city' => 'required',
    'post' => 'required'
    ]);

    Mail::send('emails.posting-message', [
    'msg'=> $request->message
    ], function($mail) use($request) {
        $mail->from($request->email, $request->name);
        $mail->to('helloworld@gmail.com')->subject('Contact Message');
    });
    return redirect()->back()->with('flash_message', 'Thank you for your message');
}

Problem Statement:

The current controller doesn't return anything as in the line 'msg'=> $request->message there is no message in validate. But if I use

'msg'=> $request->name (It returns name)

I am wondering what changes I should make in the controller so that it return every field present in the validate.

I tried with this but its only returning the last value which is post.

   'msg'=> $request->name,
   'msg'=> $request->email,
   'msg'=> $request->number,
   'msg'=> $request->city,
   'msg'=> $request->post

Don't you just want to append them all to message?

'msg'=> $request->name . "\r\n"
        . $request->email . "\r\n"
        . $request->number . "\r\n"
        . $request->city . "\r\n"
        . $request->post . "\r\n"

("\\r\\n" - carriage return + linefeed for emails.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM