0

I've created a contact form in laravel 7 and one of the fields is a simple select dropdown, it looks like this:

<select name="subject" id="subject" class="form-control">
   <option value="">Select ...</option>
   <option value="gen">General</option>
   <option value="sales">Sales</option>
</select>

When I send the form, I receive an email with the content the user filled out in the form. When an option is selected, in the email the value is displayed. I'd like to display the actual content of the select option. So not "gen" but "General" should be displayed.

Here is my controller code:

public function contactSubmit(Request $request) 
{
    $this->validate($request, [
        'name' => 'required',
        'email' => 'required|email',
        'subject' => 'required',
        'msg' => 'min:10'
    ]);

    $data = array(
        'name' => $request->name,
        'email' => $request->email,
        'subject' => $request->subject,
        'msg' => $request->msg
    );

    Mail::send('emails.contactemail', $data, function($msg) use($data) {
        $msg->from($data['email']);
        $msg->to('[email protected]');
        $msg->subject('Contact us');
    });
}

This is the blade content for the email that is sent out:

<strong>From:</strong> {{$name}}
<br>
<strong>Subject:</strong> {{$subject}}
<br>
<strong>Email:</strong> {{ $email }}
<br><br>
<strong>Message:</strong> <br><br>
{{ $msg }}
3
  • 1
    <option value="General">General</option>? Commented Oct 18, 2020 at 11:25
  • will there be a problem if you use "General" instead of "gen" in your option value? Commented Oct 18, 2020 at 11:26
  • And what's your question about this? Why not map these values in your controller? Commented Oct 18, 2020 at 11:34

2 Answers 2

3

You can leave out the value attribute, by doing so the value is taken from the text content of the option element.

<select name="subject" id="subject" class="form-control">
  <option value="">Select ...</option>
  <option>General</option>
  <option>Sales</option>
</select>

Have a look at the docs Option element

Sign up to request clarification or add additional context in comments.

Comments

1

Give value in the option to get the right output

<select name="subject" id="subject" class="form-control">
  <option value="">Select ...</option>
  <option value="General">General</option>
  <option value="Sales">Sales</option>
</select>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.