Forms and radio button selection

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
User avatar
sergei
Forum Commoner
Posts: 33
Joined: Mon Oct 06, 2003 4:17 am

Forms and radio button selection

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
sergei
Forum Commoner
Posts: 33
Joined: Mon Oct 06, 2003 4:17 am

Post 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 ?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
sergei
Forum Commoner
Posts: 33
Joined: Mon Oct 06, 2003 4:17 am

Post by sergei »

I mean, do I set the action="sendtoemailaddress" in the <form> tag
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

The action should be the name of the page that contains the PHP code that handles the form data.

Mac
Post Reply