Radio button on a form on Submit

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
podarum
Forum Commoner
Posts: 51
Joined: Mon Jun 15, 2009 1:36 pm

Radio button on a form on Submit

Post by podarum »

I have a form with 2 radio buttons at the bottom...1 is "Agree" and the second is "Don't Agree" ... On Submit I would like the form to go to POST only if the "Agree" button was pressed and go to another page (link) if the "Don;t Agree" button was selected... On Submit for both... Thanks ...
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Radio button on a form on Submit

Post by Christopher »

Not about theory or design, it's a PHP/HTML question, so moved to PHP Code.
(#10850)
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Radio button on a form on Submit

Post by califdon »

podarum wrote:I have a form with 2 radio buttons at the bottom...1 is "Agree" and the second is "Don't Agree" ... On Submit I would like the form to go to POST only if the "Agree" button was pressed and go to another page (link) if the "Don;t Agree" button was selected... On Submit for both... Thanks ...
There are a couple of ways to do that. One is to make the "Agree" button the type='submit' button and the other one a type='button' with an onClick='document.location("xxxxx.php");' or just make the "Don't Agree" an anchor <a> element. You can do fancier things with Javascript, but then occasionally you might have a visitor who has JS disabled in their browser.
podarum
Forum Commoner
Posts: 51
Joined: Mon Jun 15, 2009 1:36 pm

Re: Radio button on a form on Submit

Post by podarum »

Thank you so much Jack of Zircons, and I don't mean to sound 'goofballish", but I'm extremely new to php and web design, so I don't quite understand how that could be implemented in my code; Thank you again..

<div id="spryradio1">
<table width="673">
<tr>
<td width="334"><label>
<input type="radio" name="Disclaimer" value="I Agree" id="Disclaimer_0" />
I Agree</label></td>
<td width="327"><input name="Disclaimer" type="radio" value ="Disagree" id="Disclaimer_2"/>
Disagree</td>
</tr>
</table>
<span class="radioRequiredMsg">Please make a selection</span></div></td>
</tr>
<tr>
<td colspan="2"><p>&nbsp;</p></td>
</tr>
<tr>
<td height="34" colspan="2"><div align="center">
<input type="submit" name="Submit" id="Submit" value="Submit" />
<input type="reset" name="Reset" id="Reset" value="Reset" />
</div></td>
</tr>
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: Radio button on a form on Submit

Post by susrisha »

my suggestion :
Use javascript to validate on the client side if the selected radio button is Agree or not.
Then display an alert message if the user didnt agree.
You didnt want the form to be posted to the other page. So its better to use a client side validating javascript.

Other way:
In the posted file (action file), put an if else statement for the posted value of radio button and redirect back if the user hasnt checked on what you wanted him/her to check.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Radio button on a form on Submit

Post by califdon »

I'm afraid I can't make much sense out of that little scrap of code, because it is obviously out of context with all the references it contains. If you are not an HTML coder, though, you will have a hard time doing HTML coding, and you're probably not going to be able to pick it up in a forum like this.

Here's basically what I was saying:

Code: Select all

 
<form method='post' action='somescript.php'>
 
    // ... all the contents of your form
 
   <input type='submit' value='I Agree'>
   <input type='button' value='I Disagree' onClick='document.location("otherpage.html");'>
</form>
 
Post Reply