<form name="makeup" action="index.php" method="post">
<select id="skin_shade">
<option value="skin_shade_1">Dark</option>
<option value="skin_shade_2">Light</option>
</select></br>
Acne:<input type="checkbox" value="acne"/></br>
Oil:<input type="checkbox" value="oily"/></br>
Straight Hair:<input type="checkbox" value="straight"/></br>
<input type="submit" value="Submit"/>
</form>
<?php
echo $_POST['skin_shade']?>;
I get no output after I hit submit except for the form resetting.
Change <select id="skin_shade"> to <select name="skin_shade"> ?
Related
I have created a simple html form but I have encountered a weird problem which I have never seen before. When I click on submit then all of the data is directly passing to the URL bar. I don't know what is wrong with this can anyone help?
Form:
<form id="form-data">
Name<br><input type="text" name="name" id="name" value=""><br><br>
Age<br><input type="number" name="number" id="age" value=""><br><br>
Gender<br>
<input type="radio" name="gender" value="Male">Male
<input type="radio" name="gender" value="Female">Fe-male<br><br>
<select name="country">
<option value="Kashmir">Kashmir</option>
<option value="Egypt">Egypt</option>
<option value="Norway">Norway</option>
<option value="Iceland">Iceland</option>
</select><br>
<br><input type="submit" id="submit" value="Save">
</form>
the form uses get method therefore it displays the form values in the url. change the method to post to avoid this
method="post"
<!DOCTYPE html>
<html>
<head>
<title></title>
<body>
<form id="form-data" method="post">
Name<br><input type="text" name="name" id="name" value=""><br><br>
Age<br><input type="number" name="number" id="age" value=""><br><br>
Gender<br>
<input type="radio" name="gender" value="Male">Male
<input type="radio" name="gender" value="Female">Fe-male<br><br>
<select name="country">
<option value="Kashmir">Kashmir</option>
<option value="Egypt">Egypt</option>
<option value="Norway">Norway</option>
<option value="Iceland">Iceland</option>
</select><br>
<br><input type="submit" id="submit" value="Save">
</form>
</body>
</html>
Add method attribute to your form tag like this:
<form action="welcome.php" method="post">
https://www.w3schools.com/tags/att_form_method.asp
If you don't send the data somewhere, it gets passed as URL parameters to the current page:
From MDN Web Docs:
The action attribute defines where the data gets sent. Its value must
be a valid relative or absolute URL. If this attribute isn't provided,
the data will be sent to the URL of the page containing the form — the
current page.
I have this form:
<form action="<?php echo $php_self;?>" method="get">
<input type="submit" value="go" id="text33" />
<select name="match" id="text33" style="width:100px;">
<option value="1">1</option>
<option value="2">1</option>
</select>:select
</form>
This form is in the title page cup?c=2&match
I want to program the form so that if you press go .. go to the title page
cup?c= 2&match=1
As a function
$ cup=$_GET['c'];
$ match=$_GET['match'];
Just remove action param from tag form:
<form method="get">
<input type="submit" value="go" id="text33" />
<select name="match" id="text33" style="width:100px;">
<option value="1">1</option>
<option value="2">1</option>
</select>
</form>
Or replace your variable
$php_self
To
$_SERVER["PHP_SELF"]
i solve the problem
<form action="cup.php" method="get"><input type="hidden" value="<?php echo "2"; ?>" name="c" /><input type="submit" value="go" id="text33" /> <select name="match" id="text33" style="width:100px;"><option value="1">1</option><option value="2">2</option></select>:select</form>
thank you very much
i want to take the < select > value to the php code (above) when i press the submit button
I tried to send the form values to the same page (with action) but it didnt work.
what should I do?
<form name="open_file">
<select name="file" style="width:40%; font-size:20px;">
<option value="A1" selected="selected" >A1</option>
<option value="A2" >A2</option>
<option value="A3" >A3</option>
</select>
<button type="submit" name="submit">UPLOAD</button>
</form>
<?php
//the <select> value should be in $file.
$file= ...?
?>
thank you !
Without defining the action attribute, form element WILL NOT send the request to any page via any method.
In addition, using button, probably would the server not send the request. Use input element instead.
If you really wish to send the data to the same page, use:
<form name="open_file" action="" method="GET">
<!--your link to this page in action attribute-->
<select name="file" style="width:40%; font-size:20px;">
<option value="A1" selected="selected" >A1</option>
<option value="A2" >A2</option>
<option value="A3" >A3</option>
</select>
<input type="submit" name="submit" value="UPLOAD" />
</form>
Plus, it is not a good practice to process form data after outputting HTML. Put the PHP code at the beginning of the document.
First, you have to define your form action and method like :
<form name="open_file" action="" method='GET'>
<select name="file" style="width:40%; font-size:20px;">
<option value="A1" selected="selected" >A1</option>
<option value="A2" >A2</option>
<option value="A3" >A3</option>
</select>
<button type="submit" name="submit">UPLOAD</button>
</form>
<!-- GET YOUR SELECT VALUES USING PHP -->
<?php
if(isset($_GET['file'])){
$file = $_GET['file'];
// Now you can use $file variable according to your code requirements
}
?>
For more detail : PHP Form Handling
Form Code :
<form action="my_php.php" method="post" enctype="multipart/form-data" id="postfile">
<input type="file" name="file" id="file">
<input type="submit" name="submit" value="Submit" class="style1">
</form>
Select Tag :
<select id="lang" form="postfile">
<option value="gcc">C</option>
<option value="g++">C++</option>
<option value="javac">Java</option>
<option value="python">Python</option>
</select>
I am not able to access the $_POST["lang"] from the PHP Code.When i do:
echo $_POST["lang"];
It doesn't show anything.
No, you got to have the name="lang" attribute on your <select> tag:
<select id="lang" form="postfile" name="lang">
^ this
Reminder: Always access $_POST values, after the submission so you don't have to deal with undefined indices.
if(isset($_POST['submit'])) {
// then access your POST values
$lang = $_POST['lang'];
}
// this assumes you have an <input type="submit" name="submit" /> button
Basically, I want made a simple form in html and i want to output the all of the user input once clicked submit using php. So far its just displaying the details I entered but it doesn't get user's data to echo them out. Here are my two files
output.php:
<?php
echo 'Name: '.$POST["name"].'<br /> Gender: '.$POST["gender"].'<br />Country: '.$POST["country"];
?>
testingformphp.html (form part):
<form id="form" name="form" method="post" action="./PHP/output.php"/>
Name<input name="name" type="text" id="name"/><br/>
Gender<label><input type="radio" name="gender" id="gender_0" value="male"/>Male</label><br/>
<label><input type="radio" name="gender" id="gender_1" value="female"/>Female</label><br/>
<select name="country" id="select">
<optgroup title="europe">
<option value="Russia">Russia</option>
<option value="Greece">Greece</option>
</optgroup>
</select>
<input type="submit" id="button" value="Submit"/>
<input type="reset" id="reset" value="Reset"/>
</form>
Can anyone help?
$POST does not exists, try $_POST.
<?php
echo 'Name: '.$_POST["name"].'<br /> Gender: '.$_POST["gender"].'<br />Country: '.$_POST["country"];
?>
http://www.tizag.com/phpT/postget.php To review the post and get method.