how to change name in form month - cakephp

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))

Related

Force to POST dynamic select including empty value

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);

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 to call the value of selected option in controller?

<div class="field-wrap">
<select name=courses class="input-field1" name="state" title="state" ng-model="signup.state" >
<option value="">Select State</option>
<option value="Andaman and Nicobar Islands">Andaman and Nicobar Islands</option>
<option value="Andhra Pradesh">Andhra Pradesh</option>
<option value="Arunachal Pradesh">Arunachal Pradesh</option>
<option value="Assam">Assam</option>
<option value="Bihar">Bihar</option>
<option value="Chandigarh">Chandigarh</option>
<option value="Chhattisgarh">Chhattisgarh</option>
<option value="Dadra and Nagar Haveli">Dadra and Nagar Haveli</option>
<option value="Daman and Diu">Daman and Diu</option>
<option value="Delhi">Delhi</option>
<option value="Goa">Goa</option>
<option value="Gujarat">Gujarat</option>
<option value="Haryana">Haryana</option>
<option value="Himachal Pradesh">Himachal Pradesh</option>
<option value="Jammu and Kashmir">Jammu and Kashmir</option>
<option value="Jharkhand">Jharkhand</option>
<option value="Karnataka">Karnataka</option>
<option value="Kerala">Kerala</option>
<option value="Lakshadweep">Lakshadweep</option>
<option value="Madhya Pradesh">Madhya Pradesh</option>
<option value="Maharashtra">Maharashtra</option>
<option value="Manipur">Manipur</option>
<option value="Meghalaya">Meghalaya</option>
<option value="Mizoram">Mizoram</option>
<option value="Nagaland">Nagaland</option>
<option value="Orissa">Orissa</option>
<option value="Pondicherry">Pondicherry</option>
<option value="Punjab">Punjab</option>
<option value="Rajasthan">Rajasthan</option>
<option value="Sikkim">Sikkim</option>
<option value="Tamil Nadu">Tamil Nadu</option>
<option value="Tripura">Tripura</option>
<option value="Uttaranchal">Uttaranchal</option>
<option value="Uttar Pradesh">Uttar Pradesh</option>
<option value="West Bengal">West Bengal</option>
</select>
</div>
this is the select menu i am using i want to fetch the selected value in my controller but don't know how to do that, I already fetched the value for textbox but have no idea about the select box.
$scope.signupForm = function() {
if ($scope.signup_form.$valid) {
var data = {
firstname : $scope.signup_form.firstname.$modelValue,
lastname : $scope.signup_form.lastname.$modelValue,
email : $scope.signup_form.email.$modelValue,
mobileNumber : $scope.signup_form.mobileNumber.$modelValue,
district : $scope.signup_form.district.$modelValue,
state : $scope.signup_form.state.$modelValue,
course : $scope.signup_form.course.$modelValue,
collegeName : $scope.signup_form.collegeName.$modelValue,
};
This is my controller, I think I have to use ng-option but not sure.
Thanks
In your case $scope.signup.state will have value of selected state.
The value of selected option is saved into model assigned to dropdown
I'd suggest adding an array of options in your Controller instead of hardcoding it in the HTML and then use the ng-options directive to display the options from that array, you'd end up with something like:
<select name=courses class="input-field1" name="state" title="state" ng-model="signup.state" ng-options="option in options">
(where options is an array of options declared inside your controller
$scope.options = ['option1', 'option2'];
Then you can simply bind that input to an ng-model and use it regularly from the controller
$scope.signup.state
will give you access to whatever option is selected
You can use ng-change here. When ever an option is selected from the drop down then this method will be fired and we can persist the selected option data.
html
<div>
<select ng-model="selState" ng-change="selectedState(selState)"
data-ng-options="state as state.name for state in states">
<option value="">Select Account</option>
</select>
{{selectedState}}
</div>
script.js
myApp.controller('Ctrl', function($scope) {
$scope.states=[
{name:"AP"},
{name:"Karnataka"},
{name:"Tamilnadu"}
];
$scope.selectedState = function(item) {
alert(item.name);
};
Working Plunker

cakePHP 1.3 select types with same value but dissimilar text

i want something like below:
<select>
<option value="">Select...</option>
<option value="1">1</option>
<option value="1">2</option>
<option value="1">3</option>
</select>
i used an array for options of the select type but the array doesn't let me have an array with same index (which is value)
echo $this->Form->input('something', array('options'=>$array));
You can not create an array like:
array(1 => 1, 1 => 2, 1 => 3);
So just make it manually.
<select name="data[something]" id="something">
<option value="">Select...</option>
<option value="1">1</option>
<option value="1">2</option>
<option value="1">3</option>
</select>
Or make it the usual way and use something like jquery
$('select').on('change', function() {
$(this).val(1);
});

Resources