0

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 class="col-md-6">
            <div class="form-group">
                <label>Name<span class="redmark">&nbsp;*</span></label>
                <input type="text" class="form-control" name="firstname" id="firstname" style="margin-bottom: 3px" value="{{ Input::old('firstname') }}" placeholder="Enter Name" required="required">
            </div>
            <div class="form-group">
                <label>Email<span class="redmark">&nbsp;*</span></label>
                <div class="input-group">
                    <span class="input-group-addon"><i class="fa fa-envelope"></i></span>
                    <input type="email" class="form-control" name="email" id="email" placeholder="Email" value="{{ Input::old('email') }}" required="required">
                </div>
                <input type="checkbox" name="emailprivate" value="{{ Input::old('emailprivate') }}" id="emailprivate" style="margin-top: 3%">&nbsp;&nbsp;<span style="font-weight : 100" >Keep email private.</span>
            </div>
            <div class="form-group">
                <label>Zip Code<span class="redmark" id="zipvalidation" style="font-weight : 100;display: none">&emsp;Enter either 5 or 9 digits.</span></label>
                <input type="text" class="form-control" name="zip" id="zip" onkeydown="validateNumber(event);" maxlength="9" value="{{ Input::old('zip') }}" placeholder="Enter Zip Code">
            </div>
            <div class="form-group">
                <label>Company<span class="redmark">&nbsp;*</span></label>
                <input type="text" class="form-control" name="company" id="company" value="{{ Input::old('company') }}" placeholder="Enter Company Name">
            </div>
            <div class="form-group">
                <label>Website</label>
                <input type="url" class="form-control" name="website" id="website" value="{{ Input::old('website') }}" placeholder="Enter Website url e.g http://www.google.com">
            </div>
            <div class="form-group">
                <label>Phone Number</label>
                <div class="input-group">
                    <div class="input-group-addon">
                        <i class="fa fa-phone"></i>
                    </div>
                    <input type="text" class="form-control" name="phone" id="phone" onkeydown="validateNumber(event);" value="{{ Input::old('phone') }}" placeholder="Enter Phone number">
                </div>
            </div>
            <div class="form-group">
                <label>Free text</label>
                <textarea class="form-control" rows="2" name="freetext" id="freetext" value="{{ Input::old('freetext') }}" placeholder="Enter Text"></textarea>
            </div>
            <div class="form-group">
                <label for="exampleInputFile">Select logo</label>
                {!! Form::file('logoimage', null) !!}
                <p class="help-block"></p>
            </div>
            <!-- /.form-group -->
        </div>
        <!-- /.col -->
        <div class="col-md-6">
            <div class="form-group">
                <label>Inspection Type</label>
                <select class="form-control select2" name="inspectiontype[]" id="inspectiontype" value="{{ Input::old('inspectiontype') }}" multiple="multiple" data-placeholder="Select Inspection Type" style="width: 100%;">
                    <option value="home" selected="selected">home</option>
                    <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 class="form-group">
                <label>Company Begin Date:</label>
                <div class="input-group date">
                    <div class="input-group-addon">
                        <i class="fa fa-calendar"></i>
                    </div>
                    <input type="text" class="form-control pull-right" name="companybegindate" id="companybegindate" value="{{ Input::old('companybegindate') }}" id="datepicker">
                </div>
                <!-- /.input group -->
            </div>
            <div class="form-group">
                <label>street address 1<span class="redmark">&nbsp;*</span></label>
                <input type="text" class="form-control" name="residaddress1" id="residaddress1" value="{{ Input::old('residaddress1') }}" placeholder="Enter Street Address 1">
            </div>
            <div class="form-group">
                <label>street address 2<span class="redmark">&nbsp;*</span></label>
                <input type="text" class="form-control" name="residaddress2" id="residaddress2" value="{{ Input::old('residaddress2') }}" placeholder="Enter Street Address 2">
            </div>
            <div class="form-group">
                <label>City</label>
                <input type="text" class="form-control" name="city" id="city" value="{{ Input::old('city') }}" placeholder="Enter City">
            </div>
            <div class="form-group">
                <label>State<span class="redmark" id="statevalidation" style="font-weight : 100;display: none">&emsp;Enter two characters only e.g NJ</span></label>
                <input type="text" class="form-control"  name="state" id="state" value="{{ Input::old('state') }}" placeholder="Enter State e.g NJ">
            </div>
            <div class="form-group">
                <label>Licensing:</label>
                <input type="text" class="form-control" name="licname" id="licname" value="{{ Input::old('licname') }}" style="margin-bottom: 2px" placeholder="Enter Licensing name">
                <input type="text" class="form-control" name="licid" id="licid" style="margin-bottom: 2px" value="{{ Input::old('licid') }}" placeholder="Enter Licensing ID">
                <input type="text" class="form-control" name="licurl" id="licurl" style="margin-bottom: 2px" value="{{ Input::old('licurl') }}" placeholder="Enter URL to governing body">
            </div>
            <!-- /.form-group -->
        </div>
        <div class="col-md-12">
            <div class="box-footer pull-left">
                <button type="submit" class="btn btn-primary" onclick="return validate_data()">Create Inspector</button>
            </div>
        </div>
        {!! Form::close() !!}

Any help is much appreciated..

4
  • 1
    Can you post the code you've used to make the validator? Commented Jun 24, 2016 at 8:37
  • Yes I posted..please check now. Commented Jun 24, 2016 at 8:42
  • Do you get the same error when you send only the email to the validator i.e. $validator = Validator::make(Input::only('email'), $rules); and specifying only part of the Input in withInput()? Commented Jun 24, 2016 at 8:59
  • Yes getting same error, I'm only validating email on server side. So only passing email to the validator. Commented Jun 24, 2016 at 9:03

1 Answer 1

1

I suppose it is because you try to set input value as array.

<select class="form-control select2" name="inspectiontype[]" id="inspectiontype" value="{{ Input::old('inspectiontype') }}" multiple="multiple" data-placeholder="Select Inspection Type" style="width: 100%;">

Here you try set array of ids as value of select, but you need to add selected attribute to selected option.

{{ Input::old('inspectiontype') }}

transforms to

<?php echo htmlentities(array('id1', 'id2'), ENT_QUOTES, 'UTF-8', false)?>

I would recommend you to use laravel collective form it will do it for you

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

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.