Force to POST dynamic select including empty value - arrays

I have multiple select with the same name like this :
<select name="test[]"><option>blah....</option></select>
<select name="test[]"><option>blah....</option></select>
<select name="test[]"><option>blah....</option></select>
<select name="test[]"><option>blah....</option></select>
in php code i have :
$atest = $_POST['test'];
print_r($atest);
But, I got only data from not empty select, how to force $_POST to include all select disregarding it has value or not, so the array contains always 4 items.
thank you.

Multiple select you can use
<select name="test[]" size="7" multiple="multiple">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
</select>
After request you check $_POST['test'] is array that contains selected options
$test = $_POST['test'];
var_dump($test);

Related

how to change name in form month

I have this in my code
$this->Form->month('cc_month',['monthNames' => false]);
It generates the following code:
<select name="cc_month[month]">
<option value="" selected="selected"></option>
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>
But I only want <select name="cc_month">, without the [month] prefix. How can I do that?
The method
Cake\View\Helper\FormHelper::month(string $fieldName, array $attributes)
is meant to be used with date related fields.
The property $fieldName will be used as a prefix for the HTML name attribute of the select element, as described in Creating Date & Time Related Controls.
In your case, I understand that field month stores an integer. You can use the following code to generate the appropriate SELECT tag:
echo $this->Form->select('cc_month',range(1,12))

dropdown is not working in this code

First two lines are from js file where value is fetching through id.
var activity = document.getElementById("bactivity").value;
var activity1 = activity.options[activity.selectedIndex].value;
<select style="font-size:15px" ng-model="activity" value="Enter activity" id="bactivity">
<option selected>select</option>
<option value="Fitness">Fitness</option>
<option value="Aerobics">Aerobics</option>
<option value="Dance">Dance</option>
<option value="Martial arts">Martial arts</option>
<option value="Boxing">Boxing</option>
<option value="Athletics">Athletics</option>
</select>
the above code is from html file where I am displaying data in form of dropdown and when I am selecting any value it generate error that option is invalid. Some tell what was my mistake there so I can make it correct.
Herre you can find the working code, you just had to take the elements not their value (first 2 lines of code):
var activity = document.getElementById("bactivity");
var activity1 = activity.options[activity.selectedIndex];
<select style="font-size:15px" ng-model="activity" value="Enter activity" id="bactivity">
<option selected>select</option>
<option value="Fitness">Fitness</option>
<option value="Aerobics">Aerobics</option>
<option value="Dance">Dance</option>
<option value="Martial arts">Martial arts</option>
<option value="Boxing">Boxing</option>
<option value="Athletics">Athletics</option>
</select>

Option value is not getting selected

I am trying to select one of the option , my code is pass but at UI no option get selected .
Here is HTML code:
<select name="ddlMarketSource" id="ddlMarketSource" class="select fontb selectchange" originalvalue="0" style="width:100px;">
<option selected="selected" value="0">Select</option>
<option value="1">Call In</option>
<option value="2">Fax</option>
<option value="3">Email</option>
<option value="4">SMS</option>
<option value="5">News(Includes EPRC, Cybernet, Newspaper)</option>
<option value="6">Cold Call</option>
<option value="7">Search</option>
<option value="8">Mortgage</option>
<option value="9">Referral</option>
<option value="10">N/A</option>
</select>
Here is my statement to select :
Select mrkSource = new Select(driver.findElement(By.xpath("//*[#id='ddlMarketSource']")));
mrkSource.selectByValue("1");
Your code works on my machine.
I have selenium 2.52.0 and Firefox 44.
Try to verify if you are selecting right element. In Chrome you can open console and write
$x("//*[#id='ddlMarketSource']")
to check your xpath.

How do I bind 2 select options in AngularJS?

<select ng-model="listaAddAct.zone" ng-options="zona.route for zona in zone">
<option value="">Selected 1</option>
</select>
<select ng-model="listaAddAct.zone1" ng-options="zona1.route for zona1 in zone1">
<option value="">Selected 2</option>
</select>
What do i need:
When I make a selection in the first select and automatically my code to make a selection in the second option select.
can someone help me :)
If i have understood your question correctly. You need to use ng-change
<select ng-model="listaAddAct.zone" ng-options="zona.route for zona in zone" ng-change="listaAddAct.zone1=listaAddAct.zone">
<option value="">Selected 1</option>
</select>
i solve it :)
if($scope.zone){
$scope.zone.forEach(function(zona){
if(zona.Ruta == $scope.listaAddAct.ridicari.Nume){
$scope.listaAddAct.zone = zona;
}
});
}

Angular select ng-options hell

I'm struggling to understand to documentation for ngOptions
I have a simple array : ['code1' , 'code2'] and I just want to iterate over and construct option value and label as follow :
What I expect :
<select>
<option value="" class="">All</option>
<option value="code1">code1.label</option>
<option value="code2">code2.label</option>
</select>
What I've tried :
<select ng-model="select" ng-options="option + '.label' for option in ['code1', 'code2']">
<option value="">All</option>
</select>
What I get :
<select>
<option value="" class="">All</option>
<option value="0">code1.label</option>
<option value="1">code2.label</option>
</select>
See that values aren't what I want .. I tested almost all possible syntax of the documentation without success.
ps: I've simplified the code, but I use angular-translate to translate the received code and put that translation in the option label.
JsFiddle : http://jsfiddle.net/3ekAj/
I'm guessing what you want is:
<select ng-model="select" ng-options="option + '.label' for option in ['code1', 'code2'] track by option">
<option value="">All</option>
</select>
Fiddle: jsfiddle

Resources