I am using bootstrap 3 for my template and I am aware of the templating that exist within the Symfony Twig Bridge. Below is what I would like to have in the end.
Where I have a grey area is where I would like to have my label at 90% alignment.
Below is what I currently have:
<div class="form-group">
<div id="campaign_channel" class="col-xs-6">
<input id="campaign_channel_1" type="checkbox" value="1" name="campaign[channel][]">
<label for="campaign_channel_1">Facebook</label>
<input id="campaign_channel_2" type="checkbox" value="2" name="campaign[channel][]">
<label for="campaign_channel_2">Twiiter</label>
<input id="campaign_channel_3" type="checkbox" value="3" name="campaign[channel][]">
<label for="campaign_channel_3">LinkedIn</label>
<input id="campaign_channel_4" type="checkbox" value="4" name="campaign[channel][]">
<label for="campaign_channel_4">Instagram</label>
<input id="campaign_channel_5" type="checkbox" value="5" name="campaign[channel][]">
<label for="campaign_channel_5">Youtube</label>
</div>
</div>
Below is what I would like to have:
<div class="form-group">
<div id="campaign_channel" class="checkbox col-xs-6">
<div class="checkbox-label">Channel(s)</div>
<div class="checkbox-clmn-1">
</div>
<div class="checkbox-clmn-2">
</div>
</div>
</div>
If, as shown in the example, we have 5 checkboxes I want to split any number of checkboxes by using the multiples of three. Say have the first three checkboxes in the first column in a case where total number is odd and then if even then checkboxes should be spraed equally in both checkbox columns.
Where exactly can I create this custom template "fields.html.twig" in my Symfony application so that I can actually play around with this idea?
There is fully explained:
http://symfony.com/doc/current/cookbook/form/form_customization.html#form-theming-in-twig
You can create your own widget rendering (for ex. choice_widget) in separate file or inside file where your form is rendering
Related
I have a "questionnaire" table which contains question_id, question, and variable_scored (with rows like variable1, variable2, etc.) fields.
What I'm trying to do is generating an HTML questionnaire form based on the content of the table like so
"Question 1 here"
4 radio buttons inputs value for variable1
"Question 2 here"
4 radio buttons inputs value for variable2
Here's my code of current still static form
<div class="form-group">
<label for="input2" class="col-sm-12">Question Here</label>
<div class="col-sm-12">
<div class="radio">
<label><input type="radio" name="variable1" value='4'>4</label>
</div>
<div class="radio">
<label><input type="radio" name="variable1" value="3">3</label>
</div>
<div class="radio">
<label><input type="radio" name="variable1" value="2">2</label>
</div>
<div class="radio">
<label><input type="radio" name="variable1" value="1">1</label>
</div>
I thing you can fetch all details from controller and pass this array into view file.
And view file you can just assign this value like.
<label for="input2" class="col-sm-12"><?php echo $data['question'] ?></label>
<div class="radio">
<label><input type="radio" name="<?php echo $data['variable1'] ?>" value='4'>4</label>
</div>
You can try this one may it works for you.
I provide you also link for you.
link
I have two registration HTML form for Student and College .
Initially, I have two radio buttons of Student and College. If I select Student I'll get student registration form or if I select College I'll get college registration form also I want to insert that value of radio button to the database. I'm unable to understand how should I start. I'm using PHP and MySQLi technology. Please help me with this?
<div class="col-lg-6">
<h5>Whether College/Student?</h5>
<div class="form-group form-check-inline">
<label class="custom-control custom-radio">
<input id="radio" name="radio" value="0" type="radio" class="custom-control-input">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">College</span>
</label>
</div>
<div class="form-group form-check-inline">
<label class="custom-control custom-radio">
<input id="radio" name="radio" value="1" type="radio" class="custom-control-input">
<span class="custom-control-indicator"></span>
<span class="custom-control-description">Student</span>
</label>
</div>
</div>
First of all you need a form. You can read this article to understand how to do this and how get your form values with form tutorial
After you'll need to put those values in a database. To do that i recommand you PDO
But you probably should practice withsome tutorial before did you try to do this one?
I have the following checkboxes in my form:
<div class="form-group">
<label for="likes_turtles" class="col-md-3 control-label">Likes Turtles</label>
<div class="col-md-6">
<div class="checkbox">
<label>
<input type="checkbox" name="likes_turtles[]" value="Yes"> Yes
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="likes_turtles[]" value="No"> No
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="likes_turtles[]" value="Maybe so"> Maybe so
</label>
</div>
</div>
</div>
As you can see, they are an array of items because I want to allow selection of multiple items.
I am trying make it so that the checked items must be valid.
Here is my validation rule:
[likes_turtles] => required|in:Yes,No,Maybe so
The problem is, I'm getting the following error when I check any or all of these items:
The selected likes turtles is invalid.
How do I make laravel simply ensure any items in the request array likes_turtles belong to the specified list e.g. Yes,No,Maybe so
According to the documentation on validating arrays, you could do it like this:
[
"likes_turtles" => "required",
"likes_turtles.*" => "in:Yes,No,Maybe so"
]
How to validate if user has picked at least one checkbox by validating on the server side in Laravel 5.2
I have a simple select box:
<label for="has_driverslicense">KFZ Führerschein: </label>
<select class="form-control" required="required" id="has_driverslicense" name="has_driverslicense">
<option value="0">Nein</option>
<option value="1">Ja</option>
</select>
and a hidden div:
<div id="kfz" style="display: none;">
<div>
<input id="checkbox-20" class="checkbox-style" name="B" type="checkbox">
<label for="checkbox-20" class="checkbox-style-3-label">B (Auto bis 3,49t)</label>
</div>
<div>
<input id="checkbox-21" class="checkbox-style" name="B+E" type="checkbox">
<label for="checkbox-21" class="checkbox-style-3-label">BE (Auto mit Anhänger)</label>
</div>
<div>
<input id="checkbox-22" class="checkbox-style" name="C1" type="checkbox">
<label for="checkbox-22" class="checkbox-style-3-label">C1 (LKW bis 7,49t)</label>
</div>
<div>
<input id="checkbox-23" class="checkbox-style" name="C" type="checkbox">
<label for="checkbox-23" class="checkbox-style-3-label">C (LKW bis 40t)</label>
</div>
<div>
<input id="checkbox-24" class="checkbox-style" name="CE" type="checkbox">
<label for="checkbox-24" class="checkbox-style-3-label">CE (LKW mit Anhänger)</label>
</div>
<div>
<input id="checkbox-25" class="checkbox-style" name="fahrerkarte" type="checkbox">
<label for="checkbox-25" class="checkbox-style-3-label">Fahrerkarte</label>
</div>
<div>
<input id="checkbox-26" class="checkbox-style" name="gabelstapler" type="checkbox">
<label for="checkbox-26" class="checkbox-style-3-label">Gabelstaplerführerschein</label>
</div>
<div>
<input id="checkbox-27" class="checkbox-style" name="gelaendestapler" type="checkbox">
<label for="checkbox-27" class="checkbox-style-3-label">Geländestaplerführerschein</label>
</div>
<div>
<input id="checkbox-28" class="checkbox-style" name="IPAF" type="checkbox">
<label for="checkbox-28" class="checkbox-style-3-label">IPAF – Arbeitsbühnen</label>
</div>
</div>
When user chooses yes/ja he should choose which category does he have.
At the moment all works but i can get a user with driving licence but no category and that is baaaad! :) If you know what i mean!
Help please.
Here is the FIDDLE example
You need to name all of your checkboxes with the same name attribute, ie name="license_type" and you can then switch their names to value ie value="B".
Once this is done in your validation rules you would set.
'license_type' => 'required_if:has_driverslicense,1'
I am using codeigniter for a project. On the html side, I have 3 checkboxes in which I will see which is the checked one and store the value in database. Now I want to fetch the value and checked the corresponding checkbox.
My checkboxes is as below
<div class="span2">
<label class="radio">
<input class="attrInputs" type="radio" name="shoulder" value="flat">
Flat
</label>
<img src="http://placehold.it/126x126/cbcbcb" class="push-top">
</div>
<div class="span2">
<label class="radio">
<input class="attrInputs" type="radio" name="shoulder" value="regular">
Regular
</label>
<img src="http://placehold.it/126x126/cbcbcb" class="push-top">
</div>
<div class="span2 border-right">
<label class="radio">
<input class="attrInputs" type="radio" name="shoulder" value="sloped">
Sloped
</label>
<img src="http://placehold.it/126x126/cbcbcb" class="push-top">
</div>
So for example if I checked input element with value sloped, the value sloped will be stored in the database, when user logs in, its preloaded with its checked input of the value sloped
Thanks in advance guys!
Okay without your controller and how you're returning the data I am going to give you the basics of how this works. Essentially you're going to be checking the value of shoulder and determining the appropriate box. So in your controller you'd send data to the view something like this (again I have no idea what your db or tables looks like so this is example only).
Controller:
$this->load->model('someModel');
//the following populates the formData variable with an array from your database.
//I am going to assume you know how to do this.
$data['formData'] = $this->someModel->getData();
$this->load->view('someView',$data);
View, while it can be easier to use CI's built in form handler it's not necessary so I'll just use your code for example.
<div class="span2">
<label class="radio">
<input class="attrInputs" type="radio" name="shoulder" value="flat"
checked="<?=$formdata['shoulder'] == 'flat' ? 'checked' : '' ;?>">
Flat
</label>
<img src="http://placehold.it/126x126/cbcbcb" class="push-top">
</div>
<div class="span2">
<label class="radio">
<input class="attrInputs" type="radio" name="shoulder" value="regular"
checked="<?=$formdata['shoulder'] == 'regular' ? 'checked' : '' ;?>">
Regular
</label>
<img src="http://placehold.it/126x126/cbcbcb" class="push-top">
</div>
<div class="span2 border-right">
<label class="radio">
<input class="attrInputs" type="radio" name="shoulder" value="sloped"
checked="<?=$formdata['shoulder'] == 'sloped' ? 'checked' : '' ;?>">
Sloped
</label>
<img src="http://placehold.it/126x126/cbcbcb" class="push-top">
</div>
What the above code is doing is using a shorthand if statement to determine which box should be checked. In each one it checks if the value of 'shoulder' that your database returned is the same as the checkbox and sets it's checked value to checked if it is and blank if it isn't.
It also uses php shorttags, so if those aren't enabled on your server either enable them or adjust the php tags to read:
checked="<?php echo ($formdata['shoulder'] == 'flat' ? 'checked' : '') ;?>"