recibir etiquetas php html radio-button

etiquetas - recibir variables post php



Creación de archivo a partir de variables de botón de php (4)

Antes que nada cree un solo formulario, y coloque el <input name="submit" type="submit" value="Submit"> dentro de la etiqueta <form> .

Necesitamos ciertos parámetros para enviar el formulario, al igual que el method y el parámetro de action . Siempre use el método '' post '' para una mejor seguridad.

Ahora, modifique la etiqueta <form> con este código:

<form method="post" name="form1" action="">

Y en el parámetro ''acción'', escriba la ruta de la página en la que desea enviar el formulario y desea mostrar los valores de los botones de opción. Justo como este

<form method="post" name="form1" action="results.php">

de lo contrario, deje el parámetro de action "En blanco" al igual que la primera etiqueta <form> , si desea enviar y obtener los valores del botón de opción en la misma página.

Ahora, el código para recuperar los valores de los botones de radio:

<?php if(isset($_POST[''submit''])){ if(isset($_POST[''v1''])){ echo $_POST[''v1'']; } if(isset($_POST[''v2''])){ echo $_POST[''v2'']; } } ?>

Colóquelo justo encima de la etiqueta html.

Ahora, aquí está su código completo actualizado para una comprensión adecuada, solo copie y reemplace con su código.

<?php if(isset($_POST[''submit''])){ if(isset($_POST[''v1''])){ echo $_POST[''v1'']; } if(isset($_POST[''v2''])){ echo $_POST[''v2'']; } } ?> <!DOCTYPE html> <html> <head> <title>Config</title> <!-- Include CSS File Here--> <link href="css/style.css" rel="stylesheet"> </head> <body> <div class="container"> <div class="main"> <!---- Radio Button Starts Here -----> <form method="post" name="form1" action=""> <label class="heading">First value </label><br> <input name="v1" type="radio" value="v1text1">Value 1 - Option 1<br> <input name="v1" type="radio" value="v1text2">Value 2 - Option 1<br> <br/> <label class="heading">Second value </label><br> <input name="v2" type="radio" value="v2text1">Value 2 - Option 1<br> <input name="v2" type="radio" value="v2text2">Value 2 - Option 2<br> <input name="v2" type="radio" value="v2text3">Value 2 - Option 3 <input name="submit" type="submit" value="Submit"> </form> </div> </div> </body> </html>

Espero, esto puede ser útil para ti.

Quiero crear un archivo de texto (o al menos un eco) con algunos valores tomados de una lista de botones de opción.

Buscando información, he podido construir los formularios de radio de esta manera:

<!DOCTYPE html> <html> <head> <title>Config</title> <!-- Include CSS File Here--> <link href="css/style.css" rel="stylesheet"> </head> <body> <div class="container"> <div class="main"> <!---- Radio Button Starts Here -----> <form> <label class="heading">First value </label><br> <input name="v1" type="radio" value="v1text1">Value 1 - Option 1<br> <input name="v1" type="radio" value="v1text2">Value 2 - Option 1<br> </form> <br> <form> <label class="heading">Second value </label><br> <input name="v2" type="radio" value="v2text1">Value 2 - Option 1<br> <input name="v2" type="radio" value="v2text2">Value 2 - Option 2<br> <input name="v2" type="radio" value="v2text3">Value 2 - Option 3 </form> <input name="submit" type="submit" value="Submit"> </div> </div> </body> </html>

Y ahora me gustaría tomar los valores v1 y v2, así que encontré el siguiente código php (mi idea sería hacer esto con cada uno de los valores):

<?php if (isset($_POST[''v1''])) echo $_POST[''v1'']; else ?>

Así que lo agregué después del código del botón de envío, sin embargo, después de seleccionar valores y hacer clic en el botón Enviar, no ocurre nada.

No sé nada sobre php, el código que he escrito ha sido tomado de los hallazgos de Google.


Lo primero es que tienes dos formularios y un botón de enviar que no envía ninguno de esos dos.

Además, no tiene un punto final y esto supone que el código PHP está en el mismo archivo.

Pruebe algo como esto

<form method="POST" action="./script.php"> <label class="heading">First value </label><br> <input name="v1" type="radio" value="v1text1">Value 1 - Option 1<br> <input name="v1" type="radio" value="v1text2">Value 2 - Option 1<br> <label class="heading">Second value </label><br> <input name="v2" type="radio" value="v2text1">Value 2 - Option 1<br> <input name="v2" type="radio" value="v2text2">Value 2 - Option 2<br> <input name="v2" type="radio" value="v2text3">Value 2 - Option 3 <input name="submit" type="submit" value="Submit"> </form>


Puede intentar esto para imprimir valores.

<?php if(isset($_POST[''submit''])){ foreach($_POST as $key=>$value){ echo "Name:".$key." - Value".$value."<br />"; } } ?>


<!DOCTYPE html> <html> <head> <title>Config</title> <!-- Include CSS File Here--> <link href="css/style.css" rel="stylesheet"> </head> <body> <div class="container"> <div class="main"> <!---- Radio Button Starts Here -----> <form method="post"> <label class="heading">First value </label><br> <input name="v1" type="radio" value="v1text1">Value 1 - Option 1</input> <input name="v1" type="radio" value="v1text2">Value 2 - Option 1</input> <label class="heading">Second value </label><br> <input name="v2" type="radio" value="v2text1">Value 2 - Option 1</input> <input name="v2" type="radio" value="v2text2">Value 2 - Option 2</input> <input name="v2" type="radio" value="v2text3">Value 2 - Option 3</input> <input name="submit" type="submit" value="Submit"> </form> </div> </div> </body> </html> <?php if (isset($_POST[''v1''])) { echo $_POST[''v1'']; } if (isset($_POST[''v2''])) { echo $_POST[''v2'']; } ?>