BootStrap in laravel blade templateEngine - php

i'm using Blade template Engine in Laravel. and i want to desing forms with twitter bootstrap.
My sample Form
#section('content')
<div style='margin:20px auto;height:100px;width:300px;background-color: #fff;line-height: 1.5px'>
{{ Form::open(array('route'=>'auth', 'method'=>'post')) }}
{{ Form::text('username', Input::old('username'), array('placeholder'=>'Username', 'id'=>'username')) }}
{{ Form::password('password', array('placeholder'=>'Password', 'id'=>'password')) }}
{{ Form::submit('Login', array('id'=>'submit')) }}
{{ Form::close() }}
</div>
#stop
in this sample. how to setting that for bootstrap?

To apply the Bootstrap style to your forms, you need to pass the class "form-control" into your blade:
{{ Form::text('username', Input::old('username'), array('placeholder'=>'Username', 'id'=>'username', 'class' => 'form-control')) }}

Styling laravel/blade forms with bootstrap:
["class"=>"form-control"]

Related

How to render individual fields from DateTimeType?

How to render individual fields from DateTimeType?
{{ form_widget(form.datetime.year) }}
{{ form_widget(form.datetime.month) }}
{{ form_widget(form.datetime.day) }}
{{ form_widget(form.datetime.hour) }}
{{ form_widget(form.datetime.minute) }}
{{ form_widget(form.datetime.second) }}
Didn't work.
Or how can I have it in separate fields in the view, but in the database and Entity in one?

Symfony Customize form errors css

I'm using symfony 2.8. In registration form, when I submit form with empty fields, it is showing validation errors in tag. It is really making the UI looks bad. How can I change the css of each validation error messages.
{{ form_start(form, {'method': 'post', 'action': path('fos_user_registration_register'), 'attr': {'class': 'fos_user_registration_register','novalidate': 'novalidate'}}) }}
<div class="form-group">
{{ form_row(form.name) }}
</div>
<div class="form-group">
{{ form_row(form.email) }}
</div>
<div class="form-group">
{{ form_row(form.username) }}
</div>
<div class="form-group">
{{ form_row(form.plainPassword.first) }}
</div>
<div class="form-group">
{{ form_row(form.plainPassword.second) }}
</div>
<div>
<input type="submit" class="btn btn-primary" value="{{ 'registration.submit'|trans }}" />
</div>
{{ form_end(form) }}
You are rendering form fields using form_row widget which renders label, field & related error to do custom styling you can render your fields and their labels and errors individually like
{{ form_start(form, {'method': 'post', 'action': path('fos_user_registration_register'), 'attr': {'class': 'fos_user_registration_register','novalidate': 'novalidate'}}) }}
{{ form_label(form.email) }}
<div class="some_class">{{ form_errors(form.email) }} </div>
{{ form_widget(form.email) }}
{{ form_end(form) }}
<style type="text/css">
.some_class{
/* write custom styling rules here */
}
</style>
Or get all errors in one place like
{# render any "global" errors #}
{{ form_errors(form) }}
Reference: Twig Template Form Function and Variable Reference
The errors have their own element and classes that you could target from your css.
One basic approach could by using a form theme as described here, or you could create your own form theme.
If you want to customise the tags it renders you could do what this guy does here.

Missing required parameters for [Route: ticket.edit] [URI: ticket_ads/edit/{ad}]

I am trying to edit a record in a table. I have created a route and the form, but I can't get past this error. I have figured out the problem but I can't find a fix. Am I correct in thinking that the edit.blade.php file needs the $ad->id passing?
The $ad->id is an ID of a specific add in a List View. The list view has all the tickets displayed from a table, and the below link is meant to edit that one item.
The edit route is accessed using following code:
Edit
I have one route that is supposed to open up the edit view form:
Route::get('/ticket_ads/edit/{ad}', 'TicketAdsController#editTicketAdForm')->name('ticket.edit');
The above route points to this in the controller:
public function editTicketAdForm($id)
{
//$ad = DB::table('ticket_ads')->where('id', $id)->value('id');
return view('Ads.edit')->with('id', $id);
}
This is the view called by the above function:
#extends('Shared.Layouts.MasterWithoutMenus')
#section('title')
Edit a ticket ad
#stop
#section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading"><h2>Edit your ticket ad</h2></div> <br/>
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
{{ Form::open(array('route' => 'ticket.edit', $id = 'id')) }}
<div class="form-group">
{{ Form::label('title', 'Title') }}
{{ Form::text('title', Input::old('title'), array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('comment', 'Comment') }}
{{ Form::text('comment', Input::old('comment'), array('class' => 'form-control')) }}
</div>
{{ Form::submit('Submit', array('class' => 'btn btn-primary')) }}
{{ Form::close() }}
</div>
</div>
</div>
</div>
#endsection
This is the line that throws the error
{{ Form::open(array('route' => 'ticket.edit', $id = 'id')) }}
The ID displays normally in the URL as ticket_ads/edit/7 for example.
How do I get past this?
Change this line:
{{ Form::open(array('route' => 'ticket.edit', $id = 'id')) }}
to this:
{{Form::open(array('route' => array('ticket.edit', $id)))}}
This
{{ Form::open(array('route' => 'ticket.edit', $id = 'id')) }}
is wrong. Correct syntax is:
{{ Form::open(['route' => ['ticket.edit', $id]]) }}
also you should safely ditch using array() in favor of [] syntax as Laravel requires PHP 5.4+ anyway (unless you are using ancient version of Laravel, like v4?)
The correct syntax for calling route is.
{{ route('/cardetails', ['121','cars'] ) }}
In URL it will be like this below line.
127.0.0.1:8000/cardetails/121/cars

How to customize FOSUserBundle forms

I have below problem with FOSUserBundle customization.
I was overwritten FOSUser register form, then I changed register_content from
{{ form_widget(form) }}
to:
<div class="col-md-6">
{{ form_label(form.firstname) }}
{{ form_errors(form.firstname) }}
{{ form_widget(form.firstname) }}
{{ form_label(form.lastname) }}
{{ form_errors(form.lastname) }}
{{ form_widget(form.lastname) }}
</div>
<div class="col-md-6">
{{ form_label(form.email) }}
{{ form_errors(form.email) }}
{{ form_widget(form.email) }}
{{ form_label(form.plainPassword) }}
{{ form_errors(form.plainPassword) }}
{{ form_widget(form.plainPassword) }}
{{ form_label(form.plainPassword.second) }}
{{ form_errors(form.plainPassword.second) }}
{{ form_widget(form.plainPassword.second) }}
</div>
But, when I was went to the browser, I got it:
bad form render
The form renders incorrectly. How I can repair this?
try with this
{{ form_label(form.plainPassword.first) }}
{{ form_errors(form.plainPassword.first) }}
{{ form_widget(form.plainPassword.first) }}
{{ form_label(form.plainPassword.second) }}
{{ form_errors(form.plainPassword.second) }}
{{ form_widget(form.plainPassword.second) }}

Laravel 4.1 _token error on form submit

I am doing simple cms in laravel 4.1 , i created many form and they working fine, but the last form which i create throws error on submit.
Illuminate \ Database \ Eloquent \ MassAssignmentException
_token
The data posted by form also show on error page.
_token KLlDjuFgaEmuGHKMpFjqSrukYT3sawOYYZLPGxnb
name asdf
body asdfasdfa
bio sdfasdf
So its mean the _token is also posted then why i am getting this error.
My form look like this.
{{ Form::open(array('route' => 'admin.teachers.store','files'=>true)) }}
<ul>
<li>
{{ Form::label('image', 'Image:') }}
{{ Form::file('image') }}
</li>
<li>
{{ Form::label('name', 'Name:') }}
{{ Form::text('name') }}
</li>
<li>
{{ Form::label('body', 'Body:') }}
{{ Form::textarea('body',null,array('class'=>'ckeditor')) }}
</li>
<li>
{{ Form::label('bio', 'Bio:') }}
{{ Form::textarea('bio',null,array('class'=>'ckeditor')) }}
</li>
<li>
{{ Form::submit('Submit', array('class' => 'btn btn-info')) }}
</li>
</ul>
{{ Form::close() }}
I see one related question to _token issue on forum but it didn't help me.
Thanks in advance :)
In fact your error is MassAssignmentException, which means that you are using
Model::create($input);
In your controller and not using
protected $fillable = array('columnA', 'name'...);
or
protected $guarded = array();
In your Model, to tell Laravel which fields of your table are mass assignable.
Take a look at the docs: http://laravel.com/docs/eloquent#mass-assignment

Categories