I have a form with 3 fields and I want to go to a specific page if only one of the fields contains a value or to another page if two or more fields contain a value.
I know I need to loop through the form fields to see if only one is populated but I’m still learning and not sure how to approach this.
I was trying to use the following however I’m sure there must be an easier and simpler way as this is not giving me the required results. To some extent this works but only if the first of the fields in the form is populated but if I enter something into the second field only it will send me to the wrong page.
Thanks for any help
Code: Select all
//if (isset($_POST['v_number_1'], $_POST['v_number_2'], $_POST['v_number_3'])){
$array = array($_POST['v_number_1'], $_POST['v_number_2'], $_POST['v_number_3']);
$results=(array_count_values($array));
foreach ($results as $value=>$occurrences){
if ($occurrences == 1) {
$goTo = 'voucher_merge_update.php <br>';
} else {
$goTo = 'voucher_update_4.php <br>';
} // END if ($occurrences > 1) {
}// END foreach ($results as $value=>$occurrences){Code: Select all
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
Voucher 1:<input type="text" name="v_number_1" value="<?php if (isset($_POST['v_number_1'])) echo $_POST['v_number_1'];?>" size="32">
Voucher 2: <input type="text" name="v_number_2" value="<?php if (isset($_POST['v_number_2'])) echo $_POST['v_number_2'];?>" size="32">
Voucher 3:<input type="text" name="v_number_3" value="<?php if (isset($_POST['v_number_3'])) echo $_POST['v_number_3'];?>" size="32<input type="submit" value="Apply Vouchers">
<input type="hidden" name="MM_update" value="form1">
</form>