My HTML code is as follows:
<form action="installs.php" method="get">
<input type="radio" name="interval" value="weekly">Weekly<br>
<input type="radio" name="interval" value="monthly" checked>Monthly<br>
</form>
And my PHP is simply
$temp = $_GET["interval"];
I already have another form of buttons and a select that I am successfully retrieving input from, what am I doing wrong here?
To answer some questions, installs.php is the name of the single file that I am writing this in. There are no other elements called 'interval'.
EDIT:
When I attempted to remove all other code in order to post it here, the call stack disappeared. It seems as though the issue may be elsewhere? I will update when I find the problem.
EDIT 2:
I was mistaken about the earlier problem, I have successfully pared down the code with the problem still persisting. Now the entirety of installs.php is as such:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="installs.php" method="get">
<input type="radio" name="interval" value="weekly">Weekly<br>
<input type="radio" name="interval" value="monthly" checked>Monthly<br>
</form>
</body>
</html>
<?php
$temp = $_GET["interval"];
?>
Check if variable exists :
<form action="installs.php" method="get">
<input type="radio" name="interval" value="weekly">Weekly<br>
<input type="radio" name="interval" value="monthly" checked>Monthly<br>
</form>
<?php
if ( isset( $_GET["interval"] ) ) // <====================
$temp = $_GET["interval"];
?>
index.php
<html>
<form action="installs.php" method="get">
<input type="radio" name="interval" value="weekly">Weekly<br>
<input type="radio" name="interval" value="monthly" checked>Monthly<br>
<input type="submit" name="SEND"> <!-- ADD THIS LINE -->
</form>
</html>
installs.php:
<?php
$temp = $_GET["interval"];
echo $temp;
?>
This work fine in my webserver
try $_REQUEST['interval']; instead
Related
I have a question about radio buttons in html and linking into php. And i dont know how to link it without the name part because i need the name to be all 1 otherwise you can select every radiobutton. My second question is how do i link the button into php.
This is my HTML code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Pizza</h1>
<form method="POST" action="pizza.php">
Wat op pizza:<br>
<input type="radio" value="" name="pepperoni">Pepperoni<br>
<input type="radio" value="" name="ananas">Ananas<br>
<input type="radio" value="" name="ansjovis">Ansjovis<br>
<input type="radio" value="" name="broccoli">Broccoli<br><br>
<input type="submit" value="" name="Bestellen" value="Bestellen"><br>
</form>
</body>
</html>
So how do I say when pepperoni is selected echo "You ordered pepperoni pizza."
This is my PHP Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$pep = $_POST["pepperoni"];
$ana = $_POST["ananas"];
$ans = $_POST["ansjovis"];
$bro = $_POST["broccoli"];
?>
</body>
</html>
You can give the radio buttons all the same name with different values. So you can select 1.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Pizza</h1>
<form method="POST" action="pizza.php">
Wat op pizza:<br>
<input type="radio" value="Pepperoni" name="type">Pepperoni<br>
<input type="radio" value="Ananas" name="type">Ananas<br>
<input type="radio" value="Ansjovis" name="type">Ansjovis<br>
<input type="radio" value="Broccoli" name="type">Broccoli<br><br>
<input type="submit" name="Bestellen" value="Bestellen"><br>
</form>
</body>
</html>
And in PHP you can read
<?php
echo $_POST['type']; //Pepperoni, ananas(pineapple?) etc.
?>
Good luck!
Radio buttons let a user select ONLY ONE of a limited number of choices, There for your radio button will need to have one name attribute for that particular groups of items. Then will have different values.
Your form should look like this :
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Pizza</h1>
<form method="POST" action="pizza.php">
Wat op pizza:<br>
<input type="radio" value="pepperoni" name="pizzaType">Pepperoni<br>
<input type="radio" value="ananas" name="pizzaType">Ananas<br>
<input type="radio" value="ansjovis" name="pizzaType">Ansjovis<br>
<input type="radio" value="broccoli" name="pizzaType">Broccoli<br><br>
<input type="submit" value="Bestellen" name="Bestellen" value="Bestellen"><br>
</form>
</body>
</html>
as you can see above all the radios have the same name attribute pizzaType
Then on pizza.php you need to execute the script when the submit button is clicked, then check if an option was selected, if option was selected then return the choice user selected, if they did not return a message that the user must atleast select an item.
your pizza.php should look like:
<?php
if(isset($_POST['Bestellen'])){ //button clicked
if(isset($_POST['pizzaType'])){//check if choice is checked
echo "You ordered ".$_POST['pizzaType']. " pizza";
}else{
echo "Please select an option";
die();
}
}
?>
NB: For your own good you will also need to learn how to validate and sanitize user inputs. This is very important, you must always treat form submissions as if they from a very dangerous hacker, which it's very important to filter and sanitize the user input before using it.
If you choose a pizza you can just pick 1. So you have to give every radio the Name pizzaName for example and for value you can use the Name (pepperoni). If you press submit then you can just read the values with the PHP File like this:
$chosenPizza = $_POST['pizzaName'];
echo $chosenPizza;
And the output will be pepperoni!
Instead of having different names, make all your names the same and enter what you have as names now, as values. Then get the value by using $val = $_POST["yourvalue"];
eg:
<input type="radio" value="ananas" name="samenameforall">
$val = $_POST["samenameforall"];
You've misused the radio tag attributes a bit here. The type of pizza should be the value, not the name of the radio-button. So if you change the name to type, you can use the following line in PHP to (safely) echo out the user's choice:
// If we have something submitted, process the form,
if (isset ($_POST['order'])) {
// Pepperonies are special!
if ($_POST['type'] == 'pepperoni') {
$output = "Congrats! You ordered pepperoni!";
} else {
// Use of htmlspecialchars () to prevent XSS attacks.
$output = "You ordered ".htmlspecialchars ($_POST['type'], ENT_QUOTES, 'UTF-8')." pizza.";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Pizza</h1>
<form method="POST" action="pizza.php">
<fieldset>
<legend>Wat op pizza:</legend>
<input type="radio" id="pepp" value="pepperoni" name="type"><label for="pepp">Pepperoni</label>
<input type="radio" id="anna" value="ananas" name="type"><label for="anna">Ananas</label>
<input type="radio" id="ansj" value="ansjovis" name="type"><label for="ansj">Ansjovis</label>
<input type="radio" id="brocc" value="broccoli" name="type"><label for="broc">Broccoli</label>
</fieldset>
<fieldset>
<input type="submit" name="order" value="Bestellen">
</fieldset>
</form>
<?php
// Only show output if there is something to show.
if (!empty ($output)) {
echo "<p>$output</p>";
}
?>
</body>
</html>
Note the use of htmlspecialchars () here, as it's used to prevent XSS attacks.
When working with radio buttons, you should group them with the same name of the radio element. Take a look at this:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$toppings = filter_input(INPUT_POST, "toppings");
?>
<h1>Pizza</h1>
<form method="POST" action="pizza.php">
Wat op pizza:<br>
<input type="radio" value="pepperoni" name="toppings">Pepperoni<br>
<input type="radio" value="ananas" name="toppings">Ananas<br>
<input type="radio" value="ansjovis" name="toppings">Ansjovis<br>
<input type="radio" value="broccoli" name="toppings">Broccoli<br><br>
<input type="Submit" value="Bestellen">
<?php
echo "<br>";
if($toppings != "") {
echo "You ordered $toppings pizza. ";
}
?>
</form>
</body>
<input type="radio" value="pepperoni" name="type">Pepperoni<br>
<input type="radio" value="ananas" name="type">Ananas<br>
<input type="radio" value="ansjovis" name="type">Ansjovis<br>
<input type="radio" value="broccoli" name="type">Broccoli<br><br>
do like this .
I have a problem with my form. I need it to redirect user to different pages basing on which radio button was selected. User has to choose one of two options and click next, and according to his choice, page should redirect him to other page.
Here is the code as it looks for now
<fieldset>
<legend>Select option</legend>
<center>
<form method="post" action="">
<input type="radio" name="radio1" value="Osoba fizyczna"/>Non-company
</br>
<input type="radio" name="radio2" value="Firma"/>Company
</br>
<input type = "submit", class = "buttonStyle2", value=""/>
</form>
</center>
</fieldset>
and then php code
if(isset($_POST['Company'])
header("Location: http://myaddress.com/company.php");
Big thanks in advance for your help
Here is one way to achieve this.
Sidenote: Make sure you're not outputting before header. Consult this page on Stack about possible Headers already sent..., should this occur and making sure error reporting is set/on.
Otherwise, PHP will fail silently.
if(isset($_POST['radio1']) && ($_POST['radio1']) == "Osoba fizyczna"){
header("Location: http://www.example.com/non_company.php");
}
elseif(isset($_POST['radio1']) && ($_POST['radio1']) == "Firma"){
header("Location: http://www.example.com/company.php");
}
else{
header("Location: http://www.example.com/redirect_to_home.php");
}
Nota: The else would be if the person did not make a choice and simply clicked on submit without making a selection.
while using radio buttons of the same group name in your form:
<input type="radio" name="radio1" value="Osoba fizyczna"/>Non-company
</br>
<input type="radio" name="radio1" value="Firma"/>Company
Note about
<input type = "submit", class = "buttonStyle2", value=""/>
remove the commas
<input type = "submit" class = "buttonStyle2" value=""/>
Since HTML source in FF will reveal No space between attributes in red/as an error.
<fieldset>
<legend>Select option</legend>
<center>
<form method="post" action="">
<input type="radio" name="radio1" value="Osoba fizyczna"/>Non-company
</br>
<input type="radio" name="radio1" value="Firma"/>Company
</br>
<input type = "submit" class = "buttonStyle2" value=""/>
</form>
</center>
</fieldset>
and
if ( isset($_POST['radio1']) ) {
$filename = $_POST['radio1'] . "php";
header("Location: http://myaddress.com/".$filename);
}
Might be even better to set up an array with allowed values and check if radio1 is in that array.
My question is how do I call input value of user selected which has show by php code from another php.
Normal simple way we get the input this way
$calendar_id_val = $_GET['calendar_id'];
and now it is not working:
For example Show.php, I have one form which show the values from Database and show the result with php variable with While Loop.
<input name="calendar_id" value="<?php echo $calendar_id;?>">
and when user is submit that form I will carry these user selected value and perform insert.php
While you are doing echo in the input use echo $calendar_id_val
You should use form like,
<form action="insert.php" method="get">
<input type="text" name="calendar_id" value="<?php echo $calendar_id;?>"/>
<input type="submit" name="submit_id" value="Insert"/>
</form>
Insert.php
echo $calendar_id_val = $_GET['calendar_id'];
Does this answer your question?
<form action="insert.php" method="GET">
<input name="calendar_id" value="<?php echo $calendar_id;?>">
</form>
If you want to redirect the user back to show.php, add this to the end of your insert.php script
header('Location: show.php');
exit();
I suggest $_POST var like this:
<form action="insert.php" method="POST">
<input type="text" name="calendar_id" value="<?php echo $calendar_id;?>" />
<input type="submit" name="submit" value="Submit" />
</form>
insert.php file:
echo $calendar_id = $_POST['calendar_id'];
I've got this :
<form action="index.php" method="get">
<input type="checkbox" name="Convs_revenue"
<? echo (isset($_GET['extra_Data'])?"value='yes'":"value='no'");?>
<? if (isset($_POST['extra_Data']) ) echo 'checked="checked"'; ?> >extra_Data </input>
<input type="submit" value="send">
</form>
Now I need to keep the value of tp keep the value of the checkbox, and to unset it when its unchecked. I MUST use the GET method for this form, and this need to be at the same page as well.
What happen is that its always seem to be checked no matter what I do, and the get array always keep this at on...
Well for a start, <input /> needs no closing tag. I've also tidied up the code a little so it's a bit more readable.
I've added an extra check to make sure $_POST['extra_Data'] isn't empty. It will show up as set if it is posted empty somehow, I can't see how you're generating the POST itself.
<form action="index.php" method="get">
<input name="Convs_revenue" type="checkbox" value="<?php (isset($_GET['extra_data']) ? 'yes':'no'); ?>" <?php (isset($_POST['extra_Data']) && !empty($_POST['extra_Data'] ? 'checked="checked"' : '') ?> />
<input type="submit" value="send">
</form>
I am trying to save fields data after submited, Becouse after all the fields are good to go but lets say at the server side the user name is already taken so the form return empty and i dont want that there is the option to do it with PHP like that:
<input value="<?php if(isset($userName)) echo $userName; ?>" />
But the problem is with the radio input, If can some one think about solution about the radio with PHP i will be very thankful, Also i was thinking about Javascript so i will have cleaned code and i was thinking about taking the values from the URL but i am using POST for security reasons.
Summary: If anyone have a solution with PHP or Javascript i will be very thankful, Thank you all and have a nice day.
Try this
<form name="myform" action="" method="post">
<input type="radio" name="language" value="Java" <?php echo(#$_POST['language'] == 'Java'?"checked":""); ?> /> Java
<input type="radio" name="language" value="VB.Net" <?php echo(#$_POST['language'] == 'VB.Net'?"checked":""); ?> /> VB.Net
<input type="radio" name="language" value="PHP" <?php echo(#$_POST['language'] == 'PHP'?"checked":""); ?> /> PHP
<input type="submit" />
I think this may help you.
<input type="radio" value="choice1" name="radio_name" <?php echo(#$_POST['radio_name'] == 'on'?"checked":""); ?> />
If you want to automatically select a radio input you can add the attribute checked to it. What you are going to need will look like this :
<form method="POST">
<?php
// You have some short of list of possible value //
$arrRadioValues = array("value1", "value2", "value3");
// You display them //
for ($i=0; $i<count($arrRadioValues); $i++) {
?>
<input
type="radio"
name="radioInputName"
value="<?php echo $arrRadioValues[$i]; ?>"
<!-- If the value that was posted is the current one we have to add the "checked" so that it gets selected -->
<?php if (isset($_POST['radioInputName']) && $_POST['radioInputName'] == $arrRadioValues[$i]) { echo " checked"; } ?> />
<?php
}
?>
<input type="submit" />
</form>
Adding the checked attribute works a little bit in the same as setting a value to an input. It's just that instead of defining the value attributes, you define the checked attribute when you want that radio to be selected.