Form on Laravel 5.4?

Asked

Viewed 423 times

1

I’m having a hard time trying to create a form on Laravel 5.4, at the time of loading View appears the following error:

"Errorexception in helpers.php line 532: htmlspecialchars() expects Parameter 1 to be string, array Given (View:/var/www/html/control/Resources/views/users/create.blade.php)"

My View is like this:

<div>
{{ Form::open(array('url' => 'users')) }}

    <div class="form-group">
        {{ Form::label('name', 'Name') }}
        {{ Form::text('name', array('class' => 'form-control')) }}
    </div>

    <div class="form-group">
        {{ Form::label('email', 'Email') }}
        {{ Form::email('email', array('class' => 'form-control')) }}
    </div>

    <div class="form-group">
        {{ Form::label('nerd_level', 'User Level') }}
        {{ Form::select('nerd_level', array('0' => 'Nomal', '1' => 'Admin'), array('class' => 'form-control')) }}
    </div>

    {{ Form::submit('Create the User!', array('class' => 'btn btn-primary')) }}

{{ Form::close() }}
</div>

Someone would know how to fix it?

1 answer

1


The second parameter of email, text or textarea will always receive the current value that fills the input.

In that case, replace it with Form::text('nome', null, array('class' => 'x'))

Here’s a synopsis to simplify

Form::text($nome_do_campo, $valor_do_campo, $attributos)

Follow in the image I removed from the documentation (future references if the documentation breaks the link):

Parâmetro do form builder do laravel

See the documentation link:

  • 1

    Form::email also right?

  • @Guilhermenascimento yes, all of them. Is that the second parameter equals to value of input. Only the Form::select which changes the order, which in this case is in the third parameter.

  • now it worked, but when I click the button, the page recharges and the data is not saved in the database!

  • @Samueldesouza there would be another problem. I suggest you ask a new question

Browser other questions tagged

You are not signed in. Login or sign up in order to post.