In my profile advanced search i have an mutiple select type..
<form method="POST">
<select size="6" name="Cities" multiple="multiple" id="Cities">
<option value="0">All</option>
<option value="1">City1</option>
<option value="2">city2</option>
<option value="3">city3</option>
<option value="4">city4</option>
<option value="5">city5</option>
</select>
</form>
How do I use it, I mean how should i call what they have chosed...As you can choose one or more options (by holding in control, or just holding in mouseclick and point to other options).
Give it the name Cities[] instead of Cities, and you'll have an array in $_POST['Cities'] on submit.
google helps
http://www.onlinetools.org/tricks/using_multiple_select.php
Related
I have issues posting my select option values from html form to php back-end
Here are my codes:
<form action="submit.php" method="POST">
<select name="approver" class="form-control" autofocus>
<option selected disabled value="0">— Select Approver —</option>
<option selected disabled value="1">User A</option>
<option selected disabled value="2">User B</option>
</select>
</form>
submit.php:
$approver = mysqli_real_escape_string($conn, $_POST['approver']);
Is there a way for php to receive the value of the option, eg. 1, instead of the text inside the option tag?
Thanks in advance
"selected disabled" attributes should be used for the first option(generally which is not really an option for the user to select). It is used so that the user cannot choose the first option again after changing the option. Remove the "selected disabled" attributes from other options.
<select name="approver" class="form-control" autofocus>
<option selected disabled value="0">— Select Approver —</option>
<option value="1">User A</option>
<option value="2">User B</option>
</select>
My Multiselect input code is
<?php echo $this->Form->input('Dispensary.role.',array('options'=>$dispensary_users,'class'=>'form-control dispensary_users_dd','label'=>false,'style'=>'width:300px;','empty'=>'Select Users'));
?>
and generated html code :
<select name="data[Dispensary][role][]" class="form-control dispensary_users_dd" style="width: 300px; display: none;" id="DispensaryRole">
<option value="">Select Users</option>
<option value="9">Yashobanta</option>
<option value="80">Yash</option>
<option value="83">Ramesh</option>
</select>
But when I select all users, and print_r($this->data);
returns last selected input.
But I want all.
I forgot to add multiple => true.
I don't know how that thing with $this->Form->input(...); works, because it's not important. You can select only one opinion without multiple attribute.
Example by w3schools.org:
<select name="cars" multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
For saving the multiple select value in database, store the array using implode function.
In controller:
if (!empty($this->data)) {
$this->data['Category']['name'] = implode(",",$this->data['Category']['name']);
$this->Category->create();
$this->Category->save($this->data);
}
Hope it's help :)
I have a custom form and am trying to store multiple values in the usermeta. This is a sample code I am using, however it just stores the last option selected (i.e. if I select from Volvo to Opel, it will only store Opel in the database), whereas what I am wanting is all the values selected to be stored. Im not sure what Im doing wrong.
Any help would be appreciated.
<select name="test" id="test" multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
update_usermeta( $new_user, 'test', $_POST['test'] );
according to the wordpress codex arrays and objects are automatically serialized
http://codex.wordpress.org/Function_Reference/update_user_meta
so you shouldn't have any problems with it. if you need to grab multiple values from the select you will need to treat it as an array name="test[]" like this
<select name="test[]" id="test" multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
A select list in a form, I know there's no problem to pass the option value using post or get. But if I also want to pass the select id value, is it possible and how?
For example:
<form action="Test.php" method="POST">
<select name="select" id = '1'>
<option value="">Select a Status</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="submit" value="submit"/>
</form>
And here is the simple print php code:
<?php
print_r($_POST['select']);
?>
It can print the value of the option that has been chosen, but how to modify the code if I also want to post the id value, which is 1 here. I want to do so because I want the id to become a variable to store some int numbers. Thank you!
The id attribute is designed purely for use in client side code. If you want to pass extra data, then use hidden inputs — that is what they are designed for.
<input type="hidden" name="select_extra" value="1">
<select name="select">
<option value="">Select a Status</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
ID's won't get passed automatically in HTTP.
You need either:
Use an input hidden
Use a special name. I.E. <select name="select_1" id="1">...</select
I have 8 select fields with different options in each and im trying to pass each selected value into a querystring but im not sure how this work.
<form method="post">
<fieldset>
<legend class="hidden">Choose your options</legend>
<ol>
<li><label>option 1</label>
<select>
<option value="">Select one..</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</li>
<li><label>option 2</label>
<select>
<option value="">Select one..</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</li>
<li><label>option 3</label>
<select>
<option value="">Select one..</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</li>
</ol>
</fieldset>
</form>
so ive got 8 of these and I want to select a value from each one and then press submit which will then bring up a best match from the values passed...
Read about Dealing with Forms.
You must give the form elements a name, e.g.:
<li><label>option 1</label>
<select name="option1">
<option value="">Select one..</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</li>
Then you can access the value via $_POST['option1'].
Note: As you specified POST as form method, the data is not sent via the URL to your PHP script, but is contained in the request body. If you want to have the data in the URL (as querystring) you have to change the method to GET.
I'm nut sure exactly what you're looking for, but if you put a name=".." attribute into your select tags, they'll end up into the querystring?
You are missing NAME argument from the SELECT TAG
Once you have this, options will be received by the php script in $_POST array.
So, for example:
<SELECT NAME="mySelect">
<OPTION VALUE="V1">Value 1</OPTION>
<OPTION VALUE="V2">Value 2</OPTION>
...
</SELECT>
You would read the value in your php script from $_POST['mySelect']
Also, keep in mind that you need to enter ACTION tag for your form, defining the php script that will execute once you send your form.
Each <select> needs to have a name, for example, the first one could be <select name="firstSelection">. When you click submit, the browser sends something like firstSelection=1&secondSelection=&thirdSelection=1.