I have this html on my contact form:
<div class="form-group">
<label class="col-md-2 control-label" for="type">Type of website?</label>
<div class="col-md-10 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-file-code-o"></i></span>
<select class="form-control" id="type">
<option>Business</option>
<option>Company</option>
<option>Personal</option>
<option>Online Shopping</option>
<option>Other</option>
</select>
</div>
</div>
</div>
How can I validate and pass data of this field in email?
Currently I have this:
<!-- Text input-->
<div class="form-group">
<label class="col-md-2 control-label">Type</label>
<div class="col-md-10 inputGroupContainer">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-file-code-o"></i></span>
<input name="type" placeholder="eg. Business, Company, Personal, Online Shopping, etc." class="form-control" type="text">
</div>
</div>
</div>
And I validate and pass it like this:
$data = array(
'type' => $request->type,
);
but that's input field what I want is my first sample (select box), so I'm not sure how to do it!
thanks.
To get the exact words to validate you can make use of Rule::in method available with laravel. Using Rule::in method whatever the values provided by this rule has to be matched otherwise it will fail.
public function store(Request $request) { $data=$request->validate([ // validating the name field. 'name'=>'required']);
You can make the code powerful by using the Laravel custom validation rule with parameters. This streamlines the flow between the logic and code wherever required. Laravel offers various convenient validation rules that can be applied to the data if values are specific to a database table.
This will work perfectly.
$rules = [
'selType' => 'required|in:Business,Company,Personal,Online Shopping,Others'
];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With