Link to home
Start Free TrialLog in
Avatar of Aus2Srq
Aus2Srq

asked on

PHP: Form validation, COOKIES, RegEx and labeled addresses

I have a rather complicated address form that shows the value based on cookies being set or not. Currently if someone has been to my site and saves their addresses they are called back and displayed as an option to choose for shipping (i.e. - Work address, home address) when they log in. I also give them the option to enter a new address with a new label (i.e. - Vacation home address, etc).

My problem is when someone forgets to enter a required field or enters the info incorrectly and submits, the info is wiped out and they need to re-enter everything. My billing page did the same thing, but got that sorted via some great Experts and need some additional assistance.

Here is a snippet of my code:

<input type="text" name="ship_add_1[New]" value="<?php echo $rsShip[ship_add_1]; ?>" />

or

<select name="ship_country[New]" onchange="doUSIntl(this);">
<option value="US" >United States</option>
</select>

Where "[New]" is used to differentiate between the newly entered data and that pulled from the database as shown here:

$addrLabel = $row['shipLabel'];
...
print '<input type="hidden" name="ship_add1[' . $addrLabel . '] value="' . $row['ship_add1'] . '">';

and is submitted to:

$index = $_POST['choose_add'];
### where $_POST['choose_add'] is a radio selection with value of the respective ship label ###
if (isset($_POST['ship_add1'][$index])) { // regex cut for brevity
     $s_add1 = stripslashes($_POST['ship_add1'][$index]);
}


All this being said, I need a way if the person misses a required field or for some reason gets returned false by form validation it doesn't wipe out their data. Also, I use the if(isset(...)) if a cookie is set if they get to the end of the checkout and want to go back and edit the info they don't have to re-enter all their data. I also don't know how to get the drop down to auto select either.

Ideas?

~Aus2Srq
ASKER CERTIFIED SOLUTION
Avatar of under_dog
under_dog

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial