Jump to content

Radio Buttons


Guest Mr. Herriman

Recommended Posts

Guest Mr. Herriman

I am new to html and php. How do I add radio buttons to the same group so only one can be checked at a time? Also, how do I make it interact with some php code I have written? I want it to do work based on what radio button was pressed.

Link to comment
Share on other sites

You need to give them all the same name and different values.<input type="radio" name="radioset" value="1" checked="checked"> 1<input type="radio" name="radioset" value="2"> 2<input type="radio" name="radioset" value="3"> 3In PHP, $_POST['radioset'] (or $_GET['radioset'] depending on the action) will give you the value indicated by the value attribute of whatever they chose.

Link to comment
Share on other sites

In PHP, $_POST['radioset'] (or $_GET['radioset'] depending on the action)
Or just use this to cater for all$_REQUEST['radioset'] :)if ($_REQUEST['radioset']==1)echo "you chose 1"; elseecho "you did not choose 1";
Link to comment
Share on other sites

isn't using $_REQUEST bad? Because it looks for both get and post, the user could make a querystring variable to override your form variable and depending on your application it could be dangereous.That is what I have been told. I was told to only use $_GET and $_POST and not $_REQUEST.Is this true or is it a little paranoid?

Link to comment
Share on other sites

Is this true or is it a little paranoid?
Depends on what your using it for i would think.
The "get" method should be used when the form is idempotent (i.e., causes no side-effects). Many database searches have no visible side-effects and make ideal applications for the "get" method.If the service associated with the processing of a form causes side effects (for example, if the form modifies a database or subscription to a service), the "post" method should be used.
http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13So don't use get or request if forms modify a database, otherwise it should be ok.In this case you would be performing a check on what radio button was checked, so if they entered another value catch this using an else statement.
Link to comment
Share on other sites

What I do personally is use a function I wrote that checks $_GET first, and then $_POST.  So I don't even specify, and anything in $_POST will override $_GET.  You can also use this function:http://www.php.net/manual/en/function.impo...t-variables.phpimport_request_variables("gp", "formvar_");

Thanks that is a great idea.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...