2

I am taking values from radio buttons with the following form:

<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>

Now I want to pass those values to a php script after clicking on Submit button, so I have created another form with GET like this:

<form action="script.php" method="get">
  <input name="submit" type="submit" value="Submit">    
</form>

However, the values are not being sent to the script.php.

I also tried by putting the second form inside of the first one, but also without success.

Where is the error?

1
  • 4
    Why a second form? One form is enough to send those values. Just add the action="script.php" to the first form and all is fine. Commented Feb 23, 2017 at 11:32

5 Answers 5

4

The problem is that you are trying to post to another form. As the second form is empty and only contains the button there will be no data posted to your script.php. There is no need for a second form to submit the values from the first form :)

Change the action from your first form to script.php and forget the second form.

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

I hope this will help!

Sign up to request clarification or add additional context in comments.

Comments

1

you must make one form, two aren't needed, and cant send them with post and get same time choose only one.

 <form method="post" name="form1" 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>
    <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>

Comments

1

In you code u use 2 form, when u press submit button, it's parent form is submit,

So u can do this with simple to one form see:

<form method="post" name="form1" 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>
    <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>

Comments

1

You can just change <form method="post" name="form1" action=""> this to <form method="post" name="form1" action="script.php"> not required second one

Comments

0

step 1: Your index.php file and Method name GET

 <form method="GET" name="form1" 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>
    <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>

step 2: In your script.php write

     print_r($_GET);

     or  

     echo $_GET['v1'];
     echo $_GET['v2'];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.