1

I am building a form in Laravel, which receives dynamic input. The user can add a link in the input text, but can choose to add more links as desired. The funcionality for that was developing using jquery. The problem is that when I try to save the form (submit), I get this error message.

ErrorException in helpers.php line 531:
htmlentities() expects parameter 1 to be string, array given (View: C:\Users\jkabbas\Documents\GitProects\rastro\src\resources\views\arquiteturas\novo.blade.php)

This is the code excerpt in the laravel page, which is causing the problem. When I remove the square brackets [] from name="txt-link[]", the error message is gone, but I need to use array because I am dealing with multiple inputs.

<td>
  <input type="text" placeholder="Digite o link da arquitetura" class="form-control" id="txt-link" name="txt-link[]" value="{{old('txt-link')}}" style="width: 730px;">
  @if($errors->has('txt-link'))
    @foreach ($errors->get('txt-link') as $message)
      <span class="help-block" style="margin-top:5px; margin-bottom:-5px; color:rgb(170, 56, 56)">
        <b>{{  $message }}</b>
      </span>
    @endforeach  
  @endif  
</td>

Backend code

function store(Request $request) {
    $this->validate($request, [
        'combo_produto'=>['not_in:0'],
        'combo_projeto'=>['not_in:0'],
        'txt-link[]'=>['required'],
    ]);
    $save_arquitetura = Arquitetura::create([
        'produto_id' =>$request['combo_produto'],
        'projeto_id' =>$request['combo_projeto'],
    ]);
    return redirect('/arquiteturas')->with('msg_success', 'Dados salvos com sucesso!'); 
}
3
  • please show your backend code Commented Aug 28, 2019 at 13:58
  • function store(Request $request) { $this->validate($request, [ 'combo_produto'=>['not_in:0'], 'combo_projeto'=>['not_in:0'], 'txt-link[]'=>['required'], ]); $save_arquitetura = Arquitetura::create([ 'produto_id' =>$request['combo_produto'], 'projeto_id' =>$request['combo_projeto'] ]); return redirect('/arquiteturas')->with('msg_success', 'Dados salvos com sucesso!'); } Commented Aug 28, 2019 at 14:01
  • It too hard to read this code. Please add this code by edit your question Commented Aug 28, 2019 at 14:02

1 Answer 1

2

this is caused by value="{{old('txt-link')}}". Some kind of error occurred in your backend while you are uploading multiple files and your return all old input but you are not handling it here value="{{old('txt-link')}}. thats is the reason behind htmlentities() expects parameter 1 to be string, array given

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.