Form submit redirects to different URL's depending on particular submited value


#1

Hi everybody,
I need help regarding submitting a form. I have a html form with a radio button with “yes” and “no” responses. When someone selects “yes” and clicks submit button, I want the visitor redirected to URL1 automatically. If someone selects “no” and clicks submit button, I want the visitor redirected to URL2. I think this can be done using php or javascript. Can someone please send me the code to execute what I mentioned?

Thanks in advance


#2

very simple actually.
[php]

<?php if(isset($_POST['submit]')) { //change to the name of your submit button if($_POST['url'] == 'url1') { header('Location: someurl.com'); } elseif($_POST['url'] == 'url2') { header('Location: someurl.com'); } else { $err = "Please make a Selection!"; } } ?>[/php]

Form

<form action="" method="post">
    url 1 <input type="radio" name="url" value="url1" /><br />
    url 2 <input type="radio" name="url" value="url2" /><br />
    <input type="submit" name="submit" value="submit" />
</form
<?php
if(isset($err)) { // prevents those pesky undefined index warnings
   echo $err;
}
?>

Very basic example. Make sure the top bit of php is on top of the page, else you’ll get some header already sent errors.