Re: Quickform - shipping address same as billing checkbox
| From: | Justin Patrin | Date: | Thu, 21 Oct 2004 20:59:38 +0000 |
| Subject: | Re: Quickform - shipping address same as billing checkbox | ||
| References: | 1 2 3 4 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-15031@lists.php.net to get a copy of this message | ||
On Thu, 21 Oct 2004 14:22:47 -0400, Erik Heerlein <erik@erikheerlein.com> wrote:
> I have a form where I ask for a customer's billing and shipping
> address. I also have a, "Check here if your shipping address is the
> same as your billing address" checkbox.
>
> I have "Required" rules applied to all of the fields for both billing
> and shipping. What I was wondering is if there is a way to disable the
> required rules for the shipping address fields if the customer has
> checked the "Check here if your shipping address is the same as your
> billing address" check box.
>
> I'm thinking the logic would go something like:
>
> // if the $same_as checkbox is NOT checked
> // apply the "required" rules for the shipping address fields
>
> Also, I've heard others recommend checking the PEAR Archives but I
> cannot find a link to these archives. Thank you for your time.
>
I've got a cool system that I made for www.pnicorp.com's shopping
cart. It hides the shipping address if you check the checkbox. If you
need some JS help, let me know. However, it doesn't use QF.
So you're using QF and I assume you're doing client side validation? I
would suggest making the billing address fields client rules, then
make the shipping address required rules server-only. If the form gets
submitted with "same as" checked, you can either:
1) Just don't add the required rules. Do something like this:
if (!isset($_POST['submitted']) || !$_POST['sameAs']) {
//set up billing required rules
}
This has to be before the validation call, of course.
2) Before validation, if the "same as" box is checked, copy the
billing values into the shipping fields
if (isset($_POST['submitted'] && $_POST['sameAs'])) {
$_POST['shippingAddr'] = $_POST['billingAddr'];
}
--
paperCrane --Justin Patrin--