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.
First Give THe Name To
Select
drop down fields, then after Simplest Way Is use in Validation Rules with the name ofselect
input fields. that you giverequired
<select class="form-control" id="type" name="Business_Type">
<option value="">Select Type</option>
<option value="Business">Business</option>
<option value="Company">Company</option>
<option value="Personal">Personal</option>
<option value="Online Shopping">Online Shopping</option>
<option value="Other">Other</option>
</select>
// Validation rules somewhere...
$rules = [
...
'Business_Type' => 'required',
...
];
You need to validate your select with required
and for that you need to setup select like:
Select into blade:
<select class="form-control" id="type" name="selType">
<option value="">Select Type</option>
<option value="Business">Business</option>
<option value="Company">Company</option>
<option value="Personal">Personal</option>
<option value="Online Shopping">Online Shopping</option>
<option value="Other">Other</option>
</select>
Validation rules somewhere:
$rules = [
'selType' => 'required'
];
You can do it like this :
<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" name="typeSelection">
<option>--Select type--</option>
<option>Business</option>
<option>Company</option>
<option>Personal</option>
<option>Online Shopping</option>
<option>Other</option>
</select>
</div>
</div>
</div>
For the rules :
$rules = [
'typeSelection' => 'required|not_in:0'
];
not_in:0
to avoid submission of the first choice witch is --Select type--
:)
And to pass infos to the validation just use $request->all()
because it will use the field name
in this case typeSelection
no need for ctreating a new array !