Form with 3 dropdown menus - php

I have a form with three different dropdown menus, it looks like this:
<FORM METHOD="LINK" ACTION="/search.php" method="get">
<select style="width:55px;" name="filter_name">
<option> </option>
<option>R13</option>
<option>R14</option>
<option>R15</option>
<option>R16</option>
<option>R17</option>
</select></td></tr>
<tr><td width="40%">Plotis:</td><td colspan="2"><select style="width:55px;" name="">
<option> </option>
<option>165</option>
<option>175</option>
<option>185</option>
<option>195</option>
<option>205</option>
<option>215</option>
<option>225</option>
</select></td></tr>
<tr><td width="40%">Aukštis:</td><td colspan="2"><select style="width:55px;" name="">
<option> </option>
<option>75</option>
<option>70</option>
<option>65</option>
<option>60</option>
<option>55</option>
<option>50</option>
<option>45</option>
</select></td></tr>
<tr><td colspan="2" align="center">
<INPUT style="width:80px; height:25px; font-size:14px; font-weight:600; cursor:pointer;" TYPE="Submit" VALUE="Ieškoti">
</FORM>
Basically, I need to send all 3 Options into next page but joined into one variable..
For example: If I chose
<option>165</option>+<option>70</option>+<option>R13</option>
it should be sent to index.php like this: filter_name=165/70/R13
and also, how to send all this not to index.php only, but to
index.php?route=product/search&FILTER_NAME
Changing ACTION="/index.php" to ACTION="/index.php?route=product/search" was not working.
Any help would be really appreciated.

You could try something like this. But, you have several errors in your HTML that you should check. You have a nested table within your form.
<?php
if (!isset($_POST['send'])) {
?>
<form method="post" action="">
<select style="width:55px;" name="select_one">
<option> </option>
<option value="R13">R13</option>
<option value="R14">R14</option>
<option value="R15">R15</option>
<option value="R16">R16</option>
<option value="R17">R17</option>
</select>
<select style="width:55px;" name="select_two">
<option></option>
<option value="165">165</option>
<option value="175">175</option>
<option value="185">185</option>
<option value="195">195</option>
<option value="205">205</option>
<option value="215">215</option>
<option value="225">225</option>
</select>
<select style="width:55px;" name="select_three">
<option></option>
<option value="75">75</option>
<option value="70">70</option>
<option value="65">65</option>
<option value="60">60</option>
<option value="55">55</option>
<option value="50">50</option>
<option value="45">45</option>
</select>
<input style="width:80px; height:25px; font-size:14px; font-weight:600; cursor:pointer;" type="submit" value="send" value="Ieškoti" />
</form>
<?php
}
else {
header('Location: index.php?route=product/search&filter_name='.$_POST['select_two'].'/'.$_POST['select_three'].'/'.$_POST['select_one']);
}
?>

Join the 3 filter options in php into a variable.
$options = $_POST['f1'] . '/' . $_POST['f2'] . '/' . $_POST['f3'];
It will be less confusing IMO.

The problem can be in the invalid markup. You are using table layout, and form is split between cells. That is not valid, so may be browser renders your layout in an unexpected way.
You can expect this:
<table>
<tr>
<td>
<form>
<input>
</td>
<td>
<input>
</form>
</td>
</tr>
<table>
But browser can render your markup as this (2 forms):
<table>
<tr>
<td>
<form>
<input>
</form>
</td>
<td>
<form>
<input>
</form>
</td>
</tr>
<table>
So when you submit your form not all data are sent, cause only first form is submitted

Related

Post table rows which are checked with other select boxes

This may be a duplicate question,
But still, I did not find the answer.
My requirement is :
How to get the table rows which are CHECKED.
Here is my issue's screenshot. enter image description here
My checkbox name is 'check[]'
and the name of the select box is 'class[]',
and the form is posted to process.php.
How to get the value of 'class[]' where the checked boxes are checked so that I can then process with PHP-MYSQL?
My code is here:
<div class="col-md-5">
<form action="process.php" method="post">
<table class="table" id="table">
<tr><th>Opt</th><th>Name</th><th>Next Class</th></tr>
<? $q = $sdb->where('ac_CurClass',4)->get('tbl_accounts');
foreach ($q as $r){ ?>
<tr>
<td><input type="checkbox" name="sel[]" class="checkbox small" value="<?=$r['ac_Id'];?>"></td>
<td><?=ac_details($r['ac_Id'])->ac_Name;?></td>
<td>
<select class="form-control small" name="class[]">
<? $c = $sdb->where('c_Id',ac_details($r['ac_Id'])->ac_CurClass,">")->get("tbl_classes");
foreach($c as $d) {?>
<option value="<?=$d['c_Id'];?>"><?=$d['c_Name'];?></option>
<? } ?></select>
</td>
</tr>
<? } ?>
</table>
<button type="submit" class="btn btn-danger">Update</button>
</form>
</div>
Hope this code is help full for you
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<div class="col-md-5">
<form action="#" method="post">
<table class="table" id="table">
<thead><tr><th>Opt</th><th>Name</th><th>Next Class</th></tr></thead>
<tbody id="cont">
<tr>
<td><input type="checkbox" name="sel[]" class="checkbox small" value="1"></td>
<td>asass</td>
<td>
<select class="form-control small" name="class[]">
<option value="">Select option</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</td>
</tr>
<tr>
<td><input type="checkbox" name="sel[]" class="checkbox small" value="2"></td>
<td>asass</td>
<td>
<select class="form-control small" name="class[]">
<option value="">Select option</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</td>
</tr>
<tr>
<td><input type="checkbox" name="sel[]" class="checkbox small" value="3"></td>
<td>asass</td>
<td>
<select class="form-control small" name="class[]">
<option value="">Select option</option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select>
</td>
</tr>
</tbody>
</table>
<button type="button" class="btn btn-danger" id="submit">Update</button>
</form>
</div>
<script>
$(document).ready(function(){
$('#submit').click(function(){
$("#cont input:checkbox:checked").map(function(){
alert('Checkbox value - '+$(this).val()+' / Select Box value - '+$(this).parent().next().next('td').find('select').val());
//alert('Select Box value - '+$(this).parent().next().next('td').find('select').val());
});
});
});
</script>
After that you can pass a Ajax so that only checked rows post.
Try as follows
Post as form
<form action="process.php" method="post">
In process.php file
if($check[0]===true){
$nextclass1 = $_POST['list_box'];
}
if($check[1]===true){
$nextclass2= $_POST['list_box'];
}

html table inside form, and getting values with php

<!DOCTYPE html>
<html lang="ro">
<head>
<title>MODIFICA</title>
</head>
<body>
<?php
$select1 = isset($_POST['select1']) ? $_POST['select1'] : '';
if($select1 == 'da'){echo 'ok';}
else { echo '!ok'; }
?>
<form method="POST">
<table border="1">
<thead>
<tr>
<th>Nume</th>
<th>Prenume</th>
<th>Adresa</th>
<th>Partid</th>
<th>Consiliul Local</th>
<th>Primar</th>
<th>Consiliul Judetean</th>
<th>Presedinte Consiliul Judetean</th>
<th>Senat</th>
<th>Deputat</th>
<th>Comisia Europarlamentara</th>
<th>Presedinte</th>
<th>Submit</th>
</tr>
</thead>
<tbody>
<?php
$stmt = $db->prepare('SELECT nume,prenume,adresa,partid,consiliul_local FROM candidati');
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_OBJ)):?>
<tr>
<td><?php echo $row->nume;?></td>
<td><?php echo $row->prenume;?></td>
<td><?php echo $row->adresa;?></td>
<td><?php echo $row->partid;?></td>
<td>
<select name="select1">
<option value=""></option>
<option value="<?php echo $row->consiliul_local;?>">
<?php echo $row->consiliul_local;?>
</option>
</select>
</td>
<td>
<select name="select2">
<option value=""></option>
<option value="da">DA</option>
</select>
</td>
<td>
<select name="select3">
<option value=""></option>
<option value="da">DA</option>
</select>
</td>
<td>
<select name="select4">
<option value=""></option>
<option value="da">DA</option>
</select>
</td>
<td>
<select name="select5">
<option value=""></option>
<option value="da">DA</option>
</select>
</td>
<td>
<select name="select6">
<option value=""></option>
<option value="da">DA</option>
</select>
</td>
<td>
<select name="select7">
<option value=""></option>
<option value="da">DA</option>
</select>
</td>
<td>
<select name="select8">
<option value=""></option>
<option value="da">DA</option>
</select>
</td>
<td>
<button type="submit" name="btn">SUBMIT</button>
</td>
</tr>
<?php endwhile;?>
</tbody>
</table>
</form>
</body>
</html
I just verify if the $select1 variable is set, and if it's the case, then if the value from "option" (line 44), is 'da', then display it.
The problem that I have is that value is not displayed accordingly. Anyone knows why, and what should I change in order to work?
Or, in simple words, for starting coding the page I need, firstly I just filled-in that "option" tag with the value from db (and yes, the value 'da' is presented in 'consiliul_local' field from db), and then I made a simple echo, above the "form", and if the value of the "select" is 'da', then it should display the message 'ok'. But it always displays the message placed on the else branch. I must specify that I must do the whole logic only with php, and not js or anything else.
Here is how my page looks like, and notice that selected 'da' in the dropdown, which is there because of the MySQL fetch (line 35 in pastebin).
http://www.2shared.com/photo/eXzJ7Glo/1_online.html
This is the page source, which says the value stored in db, is correctly inserted into that value attribute of the tag.
http://www.2shared.com/uploadComplete.jsp?sId=CACRC8H4n6GrF0jJ
So I select 'da' from that dropdown, then I press the button, and I expect the 'ok' message to be displayed. Any fix? Thanks so much!

no changes in my php page

I do not understand why nothing changes in my php page when I make changes in my drop down menu.
This is the page where I test it.
http://php.aryapratinidhisabha.org.uk/excercise4.php
please see the code here
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<table>
<tr>
<td> <label for=”font”> Select Font: </label> </td>
<td> <select id=”font” name=”font”>
<option value=”Verdana”> Verdana </option>
<option value=”Arial”> Arial </option>
<option value=”Times New Roman”> Times New Roman </option>
</select>
</td>
</tr> <tr>
<td> <label for=”size”> Select Size: </label> </td>
<td> <select id=”size” name=”size”>
<option value=”10px”> 10px </option>
<option value=”12px”> 12px </option>
<option value=”16px”> 16px </option>
<option value=”20px”> 20px </option>
</select>
</td>
</tr> <tr>
<td> <label for=”color”> Select Color: </label> </td>
<td> <select id=”size” name=”size”>
<option value=”black”> black </option>
<option value=”green”> green </option>
<option value=”purple”> purple </option>
<option value=”red”> red </option>
</select>
</td>
</tr>
</form>
$_SESSION['font']=$_POST['font'];
$_SESSION['size']=$_POST['size'];
$_SESSION['color']=$_POST['color'];
<p <?php
echo ' style=”font-family: ' . $_SESSION['font'] . '; ';
echo 'font-size: ' . $_SESSION['size'] . '; ';
echo 'color: ' . $_SESSION['color']. ';" ';
?>> Text to display </p>
One, if you are not going to use jQuery or javascript, you will need to submit your form with a button or input type=submit
e.g.:
<button type="submit" >Submit</button>
or
<input type="submit" />
Also, php code that your placing within the html needs to be placed between php tags:
<html>
...
<?php
// php code here
?>
(specifically talking about the: $_SESSION globals).
Additionally, as was brought up in the comments on your question, you are going to need <form> and also to tell it where the form is submitting to.
<form method="post" action="page.php">
The method can also be get and you can also submit to the same page by leaving action="" blank. Up to you.

how to get all value in dropdownlist in php

I have a dropdown where user select some values and moves to other dropdownlist in sorted order by javascript. How can I get the chosen value in second dropdownlist in next page to a PHP variable ?
<form name="Example" action="next.php" method="post">
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<td>
<select name="Features" size="9" MULTIPLE>
<option value="2">Row 2</option>
<option value="4">Row 4</option>
<option value="5">Row 5</option>
<option value="6">Row 6</option>
<option value="7">Row 7</option>
<option value="8">Row 8</option>
<option value="9">Row 9</option>
</select>
</td>
<td align="center" valign="middle">
<input type="Button" value=">>" style="width:100px" onClick="SelectMoveRows(document.Example.Features,document.Example.FeatureCodes)">
<br>
<input type="Button" value="<<" style="width:100px" onClick="SelectMoveRows(document.Example.FeatureCodes,document.Example.Features)"><br>
<input type="Button" value=">>>>" style="width:100px" onClick="selectAll(document.Example.Features);SelectMoveRows(document.Example.Features,document.Example.FeatureCodes)"><br>
<input type="Button" value="<<<<" style="width:100px" onClick="selectAll(document.Example.FeatureCodes);SelectMoveRows(document.Example.FeatureCodes,document.Example.Features)">
</td>
<td>
<select name="FeatureCodes[]" id="FeatureCodes" size="9" MULTIPLE>
<option value="1">Row 1</option>
<option value="3">Row 3</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" value="submit" id="submit" name="submit"></td>
</tr>
</table>
Thanks in advance!!
The value of the selected element in your second form field should be in:
$_POST['FeatureCodes'][0];
If you only have one FeatureCodes form on the page then you can remove the [] from your HTML and access it using $_POST['FeatureCodes'];

How to get multiple selected values of select box in php?

I have a html form which has a select list box from which you can select multiple values because its multiple property is set to multiple. Consider form method is 'GET'. The html code for the form is as follows:
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="get" action="display.php">
<table width="300" border="1">
<tr>
<td><label>Multiple Selection </label> </td>
<td><select name="select2" size="3" multiple="multiple" tabindex="1">
<option value="11">eleven</option>
<option value="12">twelve</option>
<option value="13">thirette</option>
<option value="14">fourteen</option>
<option value="15">fifteen</option>
<option value="16">sixteen</option>
<option value="17">seventeen</option>
<option value="18">eighteen</option>
<option value="19">nineteen</option>
<option value="20">twenty</option>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" tabindex="2" /></td>
</tr>
</table>
</form>
</body>
</html>
I want to display the selected values in select list box on display.php page. So how are the selected values accessed on display.php page using $_GET[] array.
If you want PHP to treat $_GET['select2'] as an array of options just add square brackets to the name of the select element like this: <select name="select2[]" multiple …
Then you can acces the array in your PHP script
<?php
header("Content-Type: text/plain");
foreach ($_GET['select2'] as $selectedOption)
echo $selectedOption."\n";
$_GET may be substituted by $_POST depending on the <form method="…" value.
Change:
<select name="select2" ...
To:
<select name="select2[]" ...
You can use this code to retrieve values from multiple select combo box
HTML:
<form action="c3.php" method="post">
<select name="ary[]" multiple="multiple">
<option value="Option 1" >Option 1</option>
<option value="Option 2">Option 2</option>
<option value="Option 3">Option 3</option>
<option value="Option 4">Option 4</option>
<option value="Option 5">Option 5</option>
</select>
<input type="submit">
</form>
PHP:
<?php
$values = $_POST['ary'];
foreach ($values as $a){
echo $a;
}
?>
Use the following program for select the multiple values from select box.
multi.php
<?php
print <<<_HTML_
<html>
<body>
<form method="post" action="value.php">
<select name="flower[ ]" multiple>
<option value="flower">FLOWER</option>
<option value="rose">ROSE</option>
<option value="lilly">LILLY</option>
<option value="jasmine">JASMINE</option>
<option value="lotus">LOTUS</option>
<option value="tulips">TULIPS</option>
</select>
<input type="submit" name="submit" value=Submit>
</form>
</body>
</html>
_HTML_
?>
value.php
<?php
foreach ($_POST['flower'] as $names)
{
print "You are selected $names<br/>";
}
?>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="get" action="display.php">
<table width="300" border="1">
<tr>
<td><label>Multiple Selection </label> </td>
<td><select name="select2[]" size="3" multiple="multiple" tabindex="1">
<option value="11">eleven</option>
<option value="12">twelve</option>
<option value="13">thirette</option>
<option value="14">fourteen</option>
<option value="15">fifteen</option>
<option value="16">sixteen</option>
<option value="17">seventeen</option>
<option value="18">eighteen</option>
<option value="19">nineteen</option>
<option value="20">twenty</option>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" tabindex="2" /></td>
</tr>
</table>
</form>
</body>
</html>
You can iterate it directly like this
foreach ($_GET['select2'] as $value)
echo $value."\n";
or you can do it like this
$selectvalue=$_GET['select2'];
foreach ($selectvalue as $value)
echo $value."\n";
This will display the selected values:
<?php
if ($_POST) {
foreach($_POST['select2'] as $selected) {
echo $selected."<br>";
}
}
?>
// CHANGE name="select2" TO name="select2[]" THEN
<?php
$mySelection = $_GET['select2'];
$nSelection = count($MySelection);
for($i=0; $i < $nSelection; $i++)
{
$numberVal = $MySelection[$i];
if ($numberVal == "11"){
echo("Eleven");
}
else if ($numberVal == "12"){
echo("Twelve");
}
...
...
}
?>
You could do like this too. It worked out for me.
<form action="ResultsDulith.php" id="intermediate" name="inputMachine[]" multiple="multiple" method="post">
<select id="selectDuration" name="selectDuration[]" multiple="multiple">
<option value="1 WEEK" >Last 1 Week</option>
<option value="2 WEEK" >Last 2 Week </option>
<option value="3 WEEK" >Last 3 Week</option>
<option value="4 WEEK" >Last 4 Week</option>
<option value="5 WEEK" >Last 5 Week</option>
<option value="6 WEEK" >Last 6 Week</option>
</select>
<input type="submit"/>
</form>
Then take the multiple selection from following PHP code below. It print the selected multiple values accordingly.
$shift=$_POST['selectDuration'];
print_r($shift);
I fix my problem with javascript + HTML. First i check selected options and save its in a hidden field of my form:
for(i=0; i < form.select.options.length; i++)
if (form.select.options[i].selected)
form.hidden.value += form.select.options[i].value;
Next, i get by post that field and get all the string ;-)
I hope it'll be work for somebody more. Thanks to all.
foreach ($_POST["select2"] as $selectedOption)
{
echo $selectedOption."\n";
}
form submit with enctype="multipart/form-data"

Categories