php - Laravel 5.1 : htmlentities() expects parameter 1 to be string, array given
177
I'm encountering an error "htmlentities() expects parameter 1 to be string, array given", when I debug my code, this line from controller throwing the error.
return redirect()->back()->withErrors($validator)->withInput();
Controller
$rules = array(
'email' => 'required|email|unique:inspector_details', // required and must be unique in the ducks table
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
$messages = $validator->messages();
return redirect()->back()->withErrors($validator)->withInput();
}
VIEW
{!! Form::open(array('route' => 'inspector.store','class' => 'form','id' => 'createinspector','name' => 'createinspector','files' => true)) !!}
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="uid" id="uid" value="" />
<div >
<div >
<label>Name<span > *</span></label>
<input type="text" name="firstname" id="firstname" value="{{ Input::old('firstname') }}" placeholder="Enter Name" required="required">
</div>
<div >
<label>Email<span > *</span></label>
<div >
<span ><i ></i></span>
<input type="email" name="email" id="email" placeholder="Email" value="{{ Input::old('email') }}" required="required">
</div>
<input type="checkbox" name="emailprivate" value="{{ Input::old('emailprivate') }}" id="emailprivate" > <span >Keep email private.</span>
</div>
<div >
<label>Zip Code<span id="zipvalidation" > Enter either 5 or 9 digits.</span></label>
<input type="text" name="zip" id="zip" onkeydown="validateNumber(event);" maxlength="9" value="{{ Input::old('zip') }}" placeholder="Enter Zip Code">
</div>
<div >
<label>Company<span > *</span></label>
<input type="text" name="company" id="company" value="{{ Input::old('company') }}" placeholder="Enter Company Name">
</div>
<div >
<label>Website</label>
<input type="url" name="website" id="website" value="{{ Input::old('website') }}" placeholder="Enter Website url e.g http://www.google.com">
</div>
<div >
<label>Phone Number</label>
<div >
<div >
<i ></i>
</div>
<input type="text" name="phone" id="phone" onkeydown="validateNumber(event);" value="{{ Input::old('phone') }}" placeholder="Enter Phone number">
</div>
</div>
<div >
<label>Free text</label>
<textarea rows="2" name="freetext" id="freetext" value="{{ Input::old('freetext') }}" placeholder="Enter Text"></textarea>
</div>
<div >
<label for="exampleInputFile">Select logo</label>
{!! Form::file('logoimage', null) !!}
<p ></p>
</div>
<!-- /.form-group -->
</div>
<!-- /.col -->
<div >
<div >
<label>Inspection Type</label>
<select name="inspectiontype[]" id="inspectiontype" value="{{ Input::old('inspectiontype') }}" multiple="multiple" data-placeholder="Select Inspection Type" >
<option value="home" selected <option value="roof">roof</option>
<option value="asbestos">asbestos</option>
<option value="lead">lead</option>
<option value="HVAC">HVAC</option>
<option value="pest">pest</option>
<option value="septic">septic</option>
<option value="environmental">environmental</option>
<option value="plumbing">plumbing</option>
<option value="zoning">zoning</option>
<option value="mold">mold</option>
<option value="wood destroyin g organisms (WDO)">wood destroying organisms (WDO)</option>
</select>
</div>
<div >
<label>Company Begin Date:</label>
<div >
<div >
<i ></i>
</div>
<input type="text" name="companybegindate" id="companybegindate" value="{{ Input::old('companybegindate') }}" id="datepicker">
</div>
<!-- /.input group -->
</div>
<div >
<label>street address 1<span > *</span></label>
<input type="text" name="residaddress1" id="residaddress1" value="{{ Input::old('residaddress1') }}" placeholder="Enter Street Address 1">
</div>
<div >
<label>street address 2<span > *</span></label>
<input type="text" name="residaddress2" id="residaddress2" value="{{ Input::old('residaddress2') }}" placeholder="Enter Street Address 2">
</div>
<div >
<label>City</label>
<input type="text" name="city" id="city" value="{{ Input::old('city') }}" placeholder="Enter City">
</div>
<div >
<label>State<span id="statevalidation" > Enter two characters only e.g NJ</span></label>
<input type="text" name="state" id="state" value="{{ Input::old('state') }}" placeholder="Enter State e.g NJ">
</div>
<div >
<label>Licensing:</label>
<input type="text" name="licname" id="licname" value="{{ Input::old('licname') }}" placeholder="Enter Licensing name">
<input type="text" name="licid" id="licid" value="{{ Input::old('licid') }}" placeholder="Enter Licensing ID">
<input type="text" name="licurl" id="licurl" value="{{ Input::old('licurl') }}" placeholder="Enter URL to governing body">
</div>
<!-- /.form-group -->
</div>
<div >
<div >
<button type="submit" onclick="return validate_data()">Create Inspector</button>
</div>
</div>
{!! Form::close() !!}
Any help is much appreciated..
Answer
Solution:
I suppose it is because you try to set input value as array.
Here you try set
array of ids
as value of select, but you need to addselected
attribute to selected option.transforms to
I would recommend you to use laravel collective form it will do it for you