View Single Post
Old 03-07-2012, 06:49 PM   PM User | #2
dan-dan
Regular Coder

 
dan-dan's Avatar
 
Join Date: Aug 2009
Location: England
Posts: 483
Thanks: 22
Thanked 79 Times in 78 Posts
dan-dan is on a distinguished road
OK, now when you submit the form it will get validated by js and redirected.
There's a fall back with PHP as well if you want it.

PHP Code:
<?php 

error_reporting 
(E_ALL E_NOTICE);

if (
$_POST['redirect']) {
    if (isset(
$_POST['merchant']) && !empty($_POST['merchant'])) {
        
$directTo $_POST['merchant'];
        
header("location:".$directTo);
    }
    else {
        echo 
"Sorry, you did not make a selection.";
    }
}    

?>

<html>
<head>
<script>
function validate(form) {
if (document.form.merchant.value == "") {
    alert("You did not make a selection");
    return false;
    }
var directTo = document.form.merchant.value;     
window.location=directTo;
}        
</script>

</head>

<body>
<form method="post" action="" name="form" onsubmit="return validate(this);">
<fieldset>
Redirect: <select name="merchant">
<option value="" selected="yes">Please select</option>
<option value="https://www.amazon.com">amazon</option>
<option value="https://www.ebay.com">ebay</option>
<option value="https://www.bestbuy.com">bestbuy</option>
</select>
<br />
<input type="submit" name="redirect" value="Submit" />
</fieldset>
</form>
</body>

</html>

Last edited by dan-dan; 03-07-2012 at 07:38 PM..
dan-dan is offline   Reply With Quote
Users who have thanked dan-dan for this post:
aroj (03-08-2012)