Page 1 of 1

Forms and radio button selection

Posted: Tue Nov 11, 2003 8:11 am
by sergei
Hi

I've got the following piece of code that works on two radio buttons:

Code: Select all

<?
if (isset($_POST["submit"])) {
if ($issues = '4issues') {
  header("Location: http://url1goeshere"); 
} else if ($issue = '8issues') {
  header("Location: http://url2goeshere"); 
} else {

   echo("Do nothing");

}
}
?>
Basically, I want the data in the form to be sent to an email address every time it's submitted, but based on the radio button selection, the page must be redirected to a particular URL.

I've tried various ways of getting the code above to work to no avail.

If anyone has any ideas of how to get this sorted, I would really appreciate it.

Thank in advance

Posted: Tue Nov 11, 2003 8:43 am
by twigletmac
The assignment operator is =, the comparison operator is ==.

Code: Select all

if ($issues = '4issues') {
sets $issues equal to '4issues', it doesn't test whether $issues equals '4issues' as

Code: Select all

if ($issues == '4issues') {
would do.

Assuming that issues is the name of the radio button, here is a rejigging of the code:

Code: Select all

if (isset($_POST['submit'])) {
    if ($_POST['issues'] == '4issues') {
        // some code
    } elseif ($_POST['issues'] == '8issues') {
       // some code
    } else {
       // some default code
    }
}
Mac

Posted: Tue Nov 11, 2003 8:59 am
by sergei
Thanks.

How do I submit the data entered in the form to an email address and then redirect to the desired page in the if statement ?

Do I handle the form like an HTML form ?

Posted: Tue Nov 11, 2003 9:37 am
by twigletmac
You can use the [php_man]mail[/php_man]() function to send an e-mail and using [php_man]header[/php_man]() you can redirect to the page you want.

I'm not sure what you mean by 'Do I handle the form like an HTML form'.

Mac

Posted: Wed Nov 12, 2003 1:07 am
by sergei
I mean, do I set the action="sendtoemailaddress" in the <form> tag

Posted: Wed Nov 12, 2003 4:55 am
by twigletmac
The action should be the name of the page that contains the PHP code that handles the form data.

Mac