laravel blade form show me an exception error - laravel

First of all sorry for my bad english.
I have a laravel form using blade template engine that show me an exception error. If i remove the code and use the php form with echo statmente everything fine and the page show up.
where is the problem? Here is my code
{{ HTML::ul($errors->all()) }}
{{ Form::open(array('url' => 'news')) }}
<div class="form-group">
{{ Form::label('name', 'Name') }}
{{ Form::title('name', Input::old('title'), array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('email', 'Email') }}
{{ Form::text('email', Input::old('description'), array('class' => 'form-control')) }}
</div>
{{ Form::submit('Create the Nerd!', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}

There is no such thing as Form::title() in laravel.
Try this
{{ HTML::ul($errors->all()) }}
{{ Form::open(array('url' => 'news')) }}
<div class="form-group">
{{ Form::label('name', 'Name') }}
{{ Form::text('name', Input::old('title'), array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('email', 'Email') }}
{{ Form::text('email', Input::old('description'), array('class' => 'form-control')) }}
</div>
{{ Form::submit('Create the Nerd!', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
Make sure you figure these errors yourself as these are typing mistakes.

Related

Laravel form model attributes

How to pass attributes like id, class to form model?
This what i try not working and in official Laravel documentation wass not defined.
#if(isset($country))
{{ Form::model($country, ['route' => ['country.show', $country->id]], ['class' => "123"]) }}
#else
{{ Form::open(['route' => 'country.store', 'id'=> 'admin_store_form' ]) }}
#endif
<div class="row mb-2">
<div class="col-sm-1">
{{ Form::label('name', 'Name', ['class' => 'col-sm-2 admin-label col-form-label']) }}
</div>
<div class="col-sm-3">
{{ Form::text('name', old('name'), ['placeholder'=>'Name', 'class' => 'form-control form-control-sm admin-control']) }}
</div>
</div>
{{ Form::close() }}
I define 'class' => "123" but that not work.
The correct way to add a class to Form::model is:
{{ Form::model($country, ['route' => ['country.show', $country->id], 'class' => '123']) }}
You need to add the class key to the same array argument as route.

Changing laravel form to html form

Hi i created a form with laravel form helpers but i want to change it to a standard html form. The issue i am having is with the "PUT" function, when i try to edit my posts no data is displayed so i think my form properties are wrong.
Form header
<form method="post" action="{{route('posts.update',[$post->id])}}" enctype="multipart/form-data">
{{csrf_field()}}
{{method_field('put')}}
<input type=""text" name="name" class="name">
<input type=""text" name="body" class="body">
<button></button>
</form>
(--UPDATED--)
Laravel Form
{!! Form::model($post, ['route' => ['posts.update', $post->id], 'method' => 'PUT']) !!}
{{ Form::label('name', 'Name:') }}
{{ Form::text('name', null, ["class" => 'form-control input-lg']) }}
{ Form::label('body', 'Body:') }}
{{ Form::text('body', null, ["class" => 'form-control input-lg']) }}
{{ Form::submit('Save Changes', array('class' => 'btn btn-success btn-block')) }}
{{ Form::close() }}
I want the blog data to be displayed in the form for me to edit.. When i use form helpers it works fine
Any help will be much appreciated
Thanks
Ash
Ash,
I don't see the Laravel form code here to compare the two, but the easiest way to convert the Laravel form to straight HTML is to view source on the generated form and copy the generated HTML code back into the blade. Then you can replace populated data with variables.
(--UPDATED--)
Hence, put this back into your blade:
{!! Form::model($post, ['route' => ['posts.update', $post->id], 'method' => 'PUT']) !!}
{{ Form::label('name', 'Name:') }}
{{ Form::text('name', null, ["class" => 'form-control input-lg']) }}
{ Form::label('body', 'Body:') }}
{{ Form::text('body', null, ["class" => 'form-control input-lg']) }}
{{ Form::submit('Save Changes', array('class' => 'btn btn-success btn-block')) }}
{{ Form::close() }}
and then copy the HTML output for the "put" action. Or, if you're on the current version of Laravel, you can simply use the put method as follows:
#method('PUT')
(see https://laravel.com/docs/5.8/blade)
(--ORIGINAL--)
Also, you didn't mention what version of Laravel you're on. The syntax for inserting fields into the blade varies.
(--UPDATED--)
#kapitan, you're right. I "learned" that from using LaraShift telling me that all my {{ $field }} needed to be changed to {!! $field !!} to upgrade my app. The syntax has changed as follows.
In older versions of Laravel, variables inserted with {{ $field }} were UNescaped, and variables inserted with {{{ $field }}} were escaped.
In newer versions of Laravel, variables inserted with {{ $field }} are escaped, and variables inserted with {!! $field !!} are UNescaped. So the meaning of {{ $field }} has reversed from older versions to newer versions.

Resizing checkbox in form group in Laravel

<div class="col-md-3">
<div class="white-box">
{{ Form::open(['route' => ['resources.select'], 'method' => 'ANY', 'role' => 'select']) }}
<div class="form-group">
{{ Form::label('category_label', 'Categories : ') }}
{{ Form::select('category_select', $category_select, ['class'=>'form-control']) }}
{{ Form::button('Submit',['type'=>'submit','class'=>'btn btn-success waves-effect waves-light m-r-10', 'id'=>'select_resource']) }}
</div>
{{ Form::close() }}
</div>
</div>
This is my code. I have three different divisions that look the same. When I tried to change to a grid view, The select boxes stay overlapping the div block.
I want them to stay within the block in the view.
The reason why your select is overlapping is because you are missing null as a parameter in the declaration.
Change this line;
{{ Form::select('category_select', $category_select, ['class'=>'form-control']) }}
to this;
{{ Form::select('category_select', $category_select, null, ['class'=>'form-control']) }}
Also you do not need the to style the form. A more efficient way of creating the form in your question would be like the example below
<div class="col-md-3">
<div class="white-box">
{{ Form::open(['route' => ['resources.select'], 'method' => 'ANY', 'role' => 'select']) }}
<div class="form-group">
{{ Form::label('category_label', 'Categories : ') }}
{{ Form::select('category_select', $category_select, null, ['class'=>'form-control']) }}
</div>
{{ Form::button('Submit',['type'=>'submit','class'=>'btn btn-success waves-effect waves-light m-r-10', 'id'=>'select_resource']) }}
{{ Form::close() }}
</div>
</div>

Why do i have a form url point at thesame location but not at a specific file that will insert my data into database

My LoginUser.blade.php
<h1>Login</h1>
{{-- Form start comment --}}
{{ Form::open(array('url' => 'user/loginUser')) }}
<p>
{{ Form::label('email', 'E-Mail Address') }}
{{ Form::email('email', null, array("placeholder" => "Enter your email")) }}
</p>
<p>
{{ Form::label('password', 'Password') }}
{{ Form::password('password', array("placeholder"=>"Enter your password")) }}
</p>
<p>
{{ Form::submit('Sign In') }}
</p>
{{ Form::close() }}
{{-- Form end comment --}}
So my Question is why should my URL points to my current LoginUser.blade.php which contains the HTML forms?? Please am new to laravel am using laravel 5.2

displaying specific error messages in laravel 4.2

hello i have this form and i have validations for it. I have already finished doing the validations for in inside my controller and i can already display the error messages in my view but i wanted the error message to be beside the input area where it came from
here is my code in the view
{{ Form::open(array('url' => 'addParentAccnt')) }}
<div class="form-group">
{{ Form::label('username', 'Username') }}
{{ Form::text('username', Input::old('username'), array('class' => 'form-control','placeholder' => 'Insert username')) }}
</div>
<div class="form-group">
{{ Form::label('fName', 'First Name') }}
{{ Form::text('fName', Input::old('fName'), array('class' => 'form-control','placeholder' => 'Insert First Name')) }}
</div>
<div class="form-group">
{{ Form::label('lName', 'Last Name') }}
{{ Form::text('lName', Input::old('lName'), array('class' => 'form-control','placeholder' => 'Insert Last Name')) }}
</div> {{ Form::submit('Proceed to Next Step', array('class' => 'btn btn-primary')) }}
{{ Form::close()}}
in the bottom of my view i added this code to display the error messages
#if ($errors->any())
<ul>
{{ implode('', $errors->all('<p style="color:red" class="error">:message</p>')) }}
</ul>
#endif
the code inside my controller is this
$rules = array
(
'username' => 'required|min:10|max:50',
'fName' => 'required|alpha|min:1|max:80',
'lName' => 'required|alpha|min:1|max:80',
);
$validator = Validator::make(Input::all(), $rules, $messages);
if ($validator->fails())
{
return Redirect::to('createPa')
->withErrors($validator)
->withInput(Input::except('password'));
}
else
{
//do something
}
Change your view as following:
<div class="form-group">
{{ Form::label('username', 'Username') }}
{{ Form::text('username', Input::old('username'), array('class' => 'form-control','placeholder' => 'Insert username')) }}
{{ $errors->first('username', ':message') }}
</div>
<div class="form-group">
{{ Form::label('fName', 'First Name') }}
{{ Form::text('fName', Input::old('fName'), array('class' => 'form-control','placeholder' => 'Insert First Name')) }}
{{ $errors->first('fName', ':message') }}
</div>

Resources