I am making an HTML form. I want the results to appear in the PHP script.
<form action="chk_kw.php" method="post"> <br />
<select> name="website_string"
<option value="" selected="selected"></option>
<option VALUE="abc"> ABC</option>
<option VALUE="def"> def</option>
<option VALUE="hij"> hij/option>
</select>
<input type="submit" name="website_string" >
</form>
The problem is I cannot get the value passed to the PHP. if I use value:
<INPUT TYPE="submit" name="website_string" value="selected" >
It always passes the text in the quotes. In this case "selected". How do I pass one of the strings from the option?
Try this:
<form method="post" action="check.php">
<select name="website_string">
<option value="" selected="selected"></option>
<option VALUE="abc"> ABC</option>
<option VALUE="def"> def</option>
<option VALUE="hij"> hij</option>
</select>
<input TYPE="submit" name="submit" />
</form>
Both your select control and your submit button had the same name attribute, so the last one used was the submit button when you clicked it. All other syntax errors aside.
check.php
<?php
echo $_POST['website_string'];
?>
Obligatory disclaimer about using raw $_POST data. Sanitize anything you'll actually be using in application logic.
<form method="POST" action="chk_kw.php">
<select name="website_string">
<option selected="selected"></option>
<option value="abc">abc</option>
<option value="def">def</option>
<option value="hij">hij</option>
</select>
<input type="submit">
</form>
As your form gets more complex, you
can a quick check at top of your php
script using print_r($_POST);,
it'll show what's being submitted an the respective element name.
To get the submitted value of the element in question do:
$website_string = $_POST['website_string'];
It appears that in PHP you are obtaining the value of the submit button, not the select input. If you are using GET you will want to use $_GET['website_string'] or POST would be $_POST['website_string'].
You will probably want the following HTML:
<select name="website_string">
<option value="" selected="selected"></option>
<option value="abc">ABC</option>
<option value="def">def</option>
<option value="hij">hij</option>
</select>
<input type="submit" />
With some PHP that looks like this:
<?php
$website_string = $_POST['website_string']; // or $_GET['website_string'];
?>
Assuming you've fixed the syntax errors (you've closed the select box before the name attribute), you're using the same name for the select box as the submit button. Give the select box a different name.
For your actual form, if you were to just post the results to your same page, it should probably work out all right. Try something like:
<form action=<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> method="POST>
Here is what I find works
Set a form name
Use a default select option, for example...
<option value="-1" selected>Please Select</option>
So that if the form is submitted, use of JavaScript to halt the submission process can be implemented and verified at the server too.
Try to use HTML5 attributes now they are supported.
This input
<input type="submit">
should be
<input name="Submit" type="submit" value="Submit">
whenever I use a form that fails, it is a failure due to the difference in calling the button name submit and name as Submit.
You should also set your enctype attribute for your form as forms fail on my web host if it's not set.
Related
Im trying to build a web app where a user selects the value from a dropdown list and clicks the button next to the item. But only the value of select gets sent over to the next page.
echo "<td>".$row["idTaco"]."</td><td>".$row["nameTaco"]."</td><td>".$row["priceTaco"]."</td><td>".$row["descTaco"]."</td>";
?>
<td>
<form action="Includes/dodajVKosarico.inc.php?idTaco="<?php $row["idTaco"] ?> method="get">
<select name="kolicina">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<button type="submit" name="submit" class = "dodaj">Dodaj</button>
</form>
</td>
The row['idTaco'] works fine in the echo but when i try to send it using this form i cant pass the value to another page. Im sorry im still new to this.
Rather than using a query string value, one (arguably neater and easier to see) option is to just add the value again as a hidden field in your form, then it will get submitted along with the rest of the form data.
<form action="Includes/dodajVKosarico.inc.php" method="get">
<input type="hidden" name="idTaco" value="<?php echo $row["idTaco"] ?>"/>
...etc
Or you could just fix the broken quotes (and missing echo) in your existing code:
action="Includes/dodajVKosarico.inc.php?idTaco=<?php echo $row["idTaco"] ?>"
Everything is fine just missing an echo before your $row["idTaco"], You must do as follows:
<form action="Includes/dodajVKosarico.inc.php?idTaco=<?php echo $row['idTaco']; ?>" method="get">
I have a simple simple question, And is so strange for me.
In my HTML file I have a button and a form tag in which used select tag with some options as :
<form action="" method="post" name="general"> Wireless mode
<select name="wirelessmode" id="wirelessmode">
<option value="ap">AP</option>
<option value="client">Client</option>
<option value="clientbrdige">Client Bridge(Routed)</option>
<option value="adhoc">Adhoc</option>
<option value="wdsstation">WDS Station</option>
<option value="wdsap">WDS AP</option>
</select> <br>
</form>
<form action="" method="post" name="apply">
<input type="submit" name="apply" value="Apply"/>
</form>
Include that HTML file in my Php file, create a class and a function to display the selected option of the HTML as below :
<?php
include('./view/config.html');
class SSHCommand{
public function display(){
if (isset($_POST['apply'])) // press button {
$category = $_POST['wirelessmode']; // get the select option
echo $category;
}
}
}
$sshCommand=new SSHCommand();
$sshCommand->display();
?>
When i try, it gives me nothing !
But when i try :
echo 'david';
instead of
echo $category;
It prints david after press apply button.
Where I am doing wrong?
you can get a result using single FORM, modified your HTML code as per bellow.
<form action="" method="post" name="general" id="general_form"> Wireless mode
<select name="wirelessmode" id="wirelessmode">
<option value="ap">AP</option>
<option value="client">Client</option>
<option value="clientbrdige">Client Bridge(Routed)</option>
<option value="adhoc">Adhoc</option>
<option value="wdsstation">WDS Station</option>
<option value="wdsap">WDS AP</option>
</select>
<input type="submit" name="apply" value="Apply"/>
</form>
You would have to include your config.html as html with a php extension .. config.php for the html include to work.. that would be a key thing.
You can include HTML or text in a PHP include file. Anything that can go in an standard HTML file can go in a PHP include.
Your entire website should be subsequently saved using .php extensions however, whether they include php or not, that's the downside, eg. index.php rather than index.html, so it could be time-consuming. Some servers don't require this, so test your configuration first.
Best of luck
Your select is in one form block and the submit button is in another. The default nature of the submit button will submit only the html elements in that form and not all forms of the page. So to get this to work, you need to keep one form with the required elements as
<form action="" method="post" name="general"> Wireless mode
<select name="wirelessmode" id="wirelessmode">
<option value="ap">AP</option>
<option value="client">Client</option>
<option value="clientbrdige">Client Bridge(Routed)</option>
<option value="adhoc">Adhoc</option>
<option value="wdsstation">WDS Station</option>
<option value="wdsap">WDS AP</option>
</select> <br>
<input type="submit" name="apply" value="Apply"/>
</form>
I have a select tag with different values as shown below.
I want to send the selected value to a PHP page as a POST variable or any other way.
Is this possible?
<select id="city" name="city" align="left">
<option value="Pune">Pune</option>
<option value="Bhopal">Bhopal</option>
<option value="Mumbai">Mumbai</option>
<option value="New Delhi">New Delhi</option>
</select>
Put your select inside a form. Give the form an action that is a php file. give it the method of post and include a <input type="submit" value="Submit"> inside the form as well.
Then, in your php file you will access the $_POST array
echo $_POST['city'];
If you'd like to submit it without the button, you'll need to use javascipt's onChange event.
Yes, and it's very simple. You have to use the from tag : http://www.w3schools.com/html/html_forms.asp and learn a little of PHP and HTML basic interaction
<form action = 'myPage.php' method = 'post'>
<select id="city" name="city" align="left">
<option value="Pune">Pune</option>
<option value="Bhopal">Bhopal</option>
<option value="Mumbai">Mumbai</option>
<option value="New Delhi">New Delhi</option>
</select>
<input type = 'submit' name = 'send' value = 'send'/>
</form>
(I also added a button son send data)
in myPage.php :
<?php
if(isset($_POST['city'])){
echo isset($_POST['city'];
}
?>
I have a sample code:
<form action="index.php" method="get">
<select name="id">
<option value="1">One</option>
<option value="2">Two</option>
</select>
<input type="submit" value="submit" name="submit" />
</form>
When I submit form is url is "index.php?id=1" // or index.php?id=2
=> How to fix it is result "index.php?id=1&name=One" // or index.php?id=2&name=Two
I think the best approach is to populate the options from a db. Use the values as db ID numbers. Then you can store as much info as you want for each option. example:
//some sort of loop{
<option value="
<?php echo $row_option['id'];?>">
<?php echo $row_option['display_text'];?></option>
}
At the other end query db with value; use whatever data need with that value.
I have a simple problem in php select option.
The page has 5 select option & submit button. When I select a option then it should goes on specific web page. For Example: http://onlinetools.org/tricks/using_multiple_select.php
Then I select a option & press Send then It show Which option I select. But I need go specific webpage.
I have tried with this code but I have failed...
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<select name="test[]" multiple="multiple">
<option value="http://google.com">one</option>
<option value="http://yahoo.com">two</option>
<option value="http://facebook.com">three</option>
<option value="http://who.is">four</option>
<option value="http://myspace.com">five</option>
</select>
<input type="submit" value="Send" />
</form>
<?php
$test=$_POST['test'];
echo "
<script type=\"text/javascript\">
window.location = \"$test\"
</script>
";
?>
Anybody Can help me?
This should be a simple select not a multiple one since you want to redirect to only one site. here is the code :
<?php
$test=$_POST['test'];
if(isset($test)){
header("Location: $test");
}
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<select name="test">
<option value="http://google.com">one</option>
<option value="http://yahoo.com">two</option>
<option value="http://facebook.com">three</option>
<option value="http://who.is">four</option>
<option value="http://myspace.com">five</option>
</select>
<input type="submit" value="Send" />
</form>
As you've declared:
<select name="test[]" multiple="multiple">
test is an array, thus you have to take the first object of the array or remove the unused []. By the way, you can do an HTTP redirection, which is faster and works more often than javascript ones.