I'm trying to create a Twitter Bootstrap based horizontal form using Symfony and the Braincrafted Bootstrap module. I've copied the example from the docs however my form is not rendering correctly
My code is as follows
class MyController extends Controller {
/**
* #Route("/")
* #Method("GET")
* #Template
*/
public function someAction() {
$form = $this->createForm(new HorizontalFormType());
return array("horizontalForm" => $form->createView());
}
}
This class is taken from the docs:
class HorizontalFormType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('email', 'text', array(
'label' => 'Email',
'attr' => array('placeholder' => 'Email')
));
$builder->add('password', 'password', array(
'label' => 'Password',
'attr' => array('placeholder' => 'Password')
));
$builder->add('checkbox', 'checkbox', array('label' => 'Remember me'));
}
public function getName() {
return 'horizontal_form';
}
}
The template code is copied as well
<form class="form-horizontal">
<legend>Legend</legend>
{{ form_widget(horizontalForm, {'form_type': 'horizontal'}) }}
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">Sign in</button>
</div>
</div>
</form>
The resulting HTML for the form is
<form class="form-horizontal ng-pristine ng-valid">
<legend>Legend</legend>
<div id="horizontal_form">
<div>
<label class="required" for="horizontal_form_email">Email</label>
<input type="text" placeholder="Email" required="required" name="horizontal_form[email]" id="horizontal_form_email">
</div>
<div>
<label class="required" for="horizontal_form_password">Password</label>
<input type="password" placeholder="Password" required="required" name="horizontal_form[password]" id="horizontal_form_password">
</div>
<div>
<label class="required" for="horizontal_form_checkbox">Remember me</label><input type="checkbox" value="1" required="required" name="horizontal_form[checkbox]" id="horizontal_form_checkbox">
</div>
<input type="hidden" value="fea7c498a01aebd814baf4a9f57df4b6e3646195" name="horizontal_form[_token]" id="horizontal_form__token">
</div>
<div class="control-group">
<div class="controls">
<button class="btn" type="submit">Sign in</button>
</div>
</div>
</form>
Note I'm also using AngularJS in my project (hence why the ng directives are added to the form's class list).
What have I missed?
As described in the Getting Started guide in the "Form Theme" section, I had to manually configure Symfony to use the Braincrafted form template. It did not unfortunately automatically work.
twig:
form:
resources:
- "BraincraftedBootstrapBundle:Form:form_div_layout.html.twig"
For braincrafted-bootstrap up to v1.4, to make any form horizontal from within a twig,
{{ form(form, {'form_type': 'horizontal', 'attr': {'class': 'form-horizontal'}}) }}
"form-type" tells BC_Bootstrap to add the control groups for you, and the attr: class: then tells bootstrap css to apply the horizontal style. You need to have both of these applied.
This means that you don't need to extend any horizontal formTypes, nor break the form out into widgets et al in order to set the class. Just apply the form_type and class in the twig as above.
You must Wrap labels and controls in .control-group
All labels must have class .control-label.Input fields must be wrapped with div class="controls". The html output should be like this
<form class="bs-docs-example form-horizontal">
<legend>Legend</legend>
<div id="horizontal_form">
<div class="control-group">
<label for="horizontal_form_email" class="required control-label">Email</label>
<div class="controls">
<input type="text" id="horizontal_form_email" name="horizontal_form[email]" required="required" placeholder="Email">
</div>
</div>
<div class="control-group">
<label for="horizontal_form_password" class="required control-label">Password</label>
<div class="controls">
<input type="password" id="horizontal_form_password" name="horizontal_form[password]" required="required" placeholder="Password">
</div>
</div>
<div class="control-group">
<div class="controls">
<label for="horizontal_form_checkbox" class="checkbox required">
<input type="checkbox" id="horizontal_form_checkbox" name="horizontal_form[checkbox]" required="required" value="1"> Remember me
</label>
</div>
</div>
<input type="hidden" id="horizontal_form__token" name="horizontal_form[_token]" value="def76ca43f623d0a4ad8145e39f33907b7e9e0a1"></div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn">Sign in</button>
</div>
</div>
</form>
Related
I want to play with this fields,i want to insert description1,description2 data into this description[] how to do that i tried but something is missing.
<div class="form-group row">
<label for="description" class="col-md-4 col-form-label">Description</label>
<div class="col-md-8">
<input type="text" class="form-control" name="description[]" placeholder="Enter description">
</div>
</div>
<div class="form-group row">
<label for="description" class="col-md-4 col-form-label">Description 1 (optional)</label>
<div class="col-md-8">
<input type="text" class="form-control" name="description2" placeholder="Enter description">
</div>
</div>
<div class="form-group row">
<label for="description" class="col-md-4 col-form-label">Description 2 (optional)</label>
<div class="col-md-8">
<input type="text" class="form-control" name="description3" placeholder="Enter description">
</div>
</div>
public function store(Request $request)
{
$description1 = $request->input('description1');
$description2 = $request->input('description2');
$products = new ProductAdd;
$prodduct->name = $request('name');
$prodduct->description[] = [
'description1' => $description1;
'description2' => $description2;
];
$product->save();
}
If you cast the description field to be an array in your model, you can update your controller code to:
$prodduct->description = [
'description1' => $description1;
'description2' => $description2;
];
To cast the field to an array, add this to your ProductAdd Model:
$casts = [
'description' => 'array'
];
I am trying to log a user in and take them to a page that displays content based on a slug.
I get this error :
ErrorException in ApplicantLoginController.php line 21:
Missing argument 2 for App\Http\Controllers\Auth\ApplicantLoginController::Login()
This is my controller :
public function Login(Request $request, $slug){
//Validate the form
$this->validate($request, [
'email' => 'required',
'password' => 'required',
'agree' => 'required'
]);
//Attempt to log the user in
if (Auth::guard('applicant')->attempt(['email' => $request->email,'password' => $request->password] )) {
$house = House::where('slug', '=', $slug)->first();
return view('client.index')->withHouse($house);
}
return redirect()->back()->withInput($request->only('email'));
}
This is the route to the page I am taking them to after login :
Route::get('client/index/{slug}', ['as' => 'client.index', 'uses' => 'ClientRegistrationController#index']);
This are my login routes :
Route::get('client/login', 'Auth\ApplicantLoginController#ShowLoginForm')->name('client.login');
Route::post('/client/login', 'Auth\ApplicantLoginController#Login')->name('client.login.submit');
Any ideas on how I can solve this problem?
This the button that takes the user to the page with the content based on a slug
Book now
If the user is not logged in the page redirects to this login page:
<form class="form-horizontal" role="form" method="POST" action="{{ route('client.login.submit') }}">
<input name="_token" type="hidden" value="{{ csrf_token()}}"/>
<div class="form-group">
<label for="email" class="col-md-3 control-label"></label>
<div class="col-md-6">
<input type="email" class="form-control" placeholder="Your Email" name="email" required="">
</div>
</div>
<div class="form-group">
<label for="password" class="col-md-3 control-label"></label>
<div class="col-md-6">
<input type="password" class="form-control" placeholder="Password" name="password" required="">
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<div class="checkbox">
<label>
<input type="checkbox" name="remember"> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<div class="checkbox">
<label>
<input type="checkbox" name="agree" required=""> I have read and accepted the terms and condition
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-3">
<input type="submit" value="Login" class="btn btn-primary">
</input>
<a class="btn btn-link" href="#">
Forgot Your Password?
</a>
</div>
</div>
</form>
You should have $slug declared in the post route:
Route::post('/client/login/{slug}', 'Auth\ApplicantLoginController#Login')->name('client.login.submit');
And change your form to add the parameter:
<form class="form-horizontal" role="form" method="POST" action="{{ route('client.login.submit', ['slug' => $slug]) }}">
In my project on the user edit page I would like to show the current role,wich i get by findOne byId,but I would also like to get all available roles so that I can choose, roles are in a separate collection, and I dont have a problem when displaying eather one...or all..
<div class="form-group col-lg-12">
<label>Email</label>
<input type="email" class="form-control" id="email" value="{{emails.[0].address}}">
</div>
<div class="form-group col-lg-12">
<label>Password</label>
<input type="password" name="" class="form-control" id="password" value="{{password}}">
</div>
<div class="form-group col-lg-6">
<label>Name</label>
<input type="text" name="" class="form-control" id="firstname" value="{{profile.name}}">
</div>
<div class="col-xs-12"><strong>Current role:</strong>
<label class="radio-inline">
<input type="radio" name="optradio" id="accountRole" value="{{roleName profile.role}}" checked>{{roleName profile.role}}
</label>
</div>
{{/with}}
<div class="col-xs-12">
<form>
<div class="col-xs-12"><strong>Roles:</strong>
{{#each rolesInformation}}
<label class="radio-inline">
<input type="radio" name="optradio" id="accountRole" value="{{_id}}">{{roleName}}
</label>
{{/each}}</div>`
helpers look like this:
Template.editUser2.helpers({
user: () => {
return Meteor.users.findOne({_id:Session.get('id')});
},
playerInformation: () => {
return Players.find().fetch();
},
roleName: (id)=>{
return Roles.findOne({_id:id}).roleName;
},
rolesInformation: () =>{
return Roles.find().fetch();
},
when i run roleName or rolesInformation separateli it works fine...
whet both included i get "roleName not defined"
I have the following code:
JS
.if(() => { return this.HasProvidedEitherSku1OrSku2 === false })
.isNotEmpty().withMessage(‘at least one sku is required')
.hasLengthBetween(0, 50)
.endIf()
.ensure('Sku2', (config) => {config.computedFrom(['Sku1'])})
.if(() => { return this.HasProvidedEitherSku1OrSku2 === false })
.isNotEmpty().withMessage(‘at least one sku is required’)
.hasLengthBetween(0, 50)
.endIf();
HTML
<div class="col-sm-6">
<div class="form-group">
<label class="control-label">SKU</label>
<input disabled.bind="readonly" type="text" class="form-control" value.bind="Sku1">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="control-label"> SKU</label>
<input disabled.bind="readonly" type="text" class="form-control" value.bind="Sku2">
</div>
</div>
withMessage seens to react differently when contained within an if statement. rather than adding a 'has-warning' to the form-group. It just adds:
<p class="help-block **aurelia-validation-message**">at least one sku is required</p>
How do I force a 'has-warning'? Or have something close to an if statement. If p class = "" then grab label above and input below.
Is there a way to change the html output from wp_login_form(), so that is like the bootstrap form?
The wp_login_form looks like this:
<form class="form-grey" name="loginform" id="loginform" action="http://domain.loc/wp-login.php" method="post">
<p class="login-username">
<label for="user_login">Username</label>
<input type="text" name="log" id="user_login" class="input" value="" size="20">
</p>
<p class="login-password">
<label for="user_pass">Password</label>
<input type="password" name="pwd" id="user_pass" class="input" value="" size="20">
</p>
<p class="login-remember"><label><input name="rememberme" type="checkbox" id="rememberme" value="forever"> Remember Me</label></p>
<p class="login-submit">
<input type="submit" name="wp-submit" id="wp-submit" class="button-primary" value="Log In">
<input type="hidden" name="redirect_to" value="http://domain.loc/">
</p>
</form>
And Bootstrap Forms look like this:
<form class="form-inline">
<div class="form-group">
<label class="sr-only" for="exampleInputEmail3">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail3" placeholder="Email">
</div>
<div class="form-group">
<label class="sr-only" for="exampleInputPassword3">Password</label>
<input type="password" class="form-control" id="exampleInputPassword3" placeholder="Password">
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
<button type="submit" class="btn btn-default">Sign in</button>
</form>
Try to use this :
Take your arguments as per the classes and IDs required :
$args = array(
'echo' => true,
'redirect' => property_list(),
'form_id' => 'loginform',
'label_username' => '',
'label_password' => '',
'label_remember' => __('Keep me logged in'),
'label_log_in' => __('SIGN IN'),
'id_username' => 'user_login',
'id_password' => 'user_pass',
'id_remember' => 'rememberme',
'id_submit' => 'wp-submit',
'remember' => true,
'value_username' => NULL,
'value_remember' => false
);
Now pass this $args array to function below :
<?php wp_login_form_custom($args);?>
Now you can use this function as defined below :
function wp_login_form_custom($args = array()) {
//you can use the values as $args['form_id'] and so on
//create you own HTML here with classes and IDs defined in the $args
}