What I would do is make checkboxes for each picture (that way people
can buy more than one thing).
So on your gallery page, you would have a checkbox under each picture.
This checkbox would be named for the item it refers to, so let’s say
you had pictures of Stooges for sale, you would have a checkbox named
larry, another named curly, and another named moe. If someone is
seriously into their Stooges, then when this form was posted to the
next page – the one with the send us your money stuff on it – then
it would arrive looking like this:
larry => '1',
curly => '1',
moe => '1',
submit => 'Submit'
If they only wanted one Stooge, then the array would only have one
element and the Submit button. Checkboxes will be sent by the browser
if they are checked, and they don’t get sent if they are not checked.
So let’s say then that your order page had fields for name, address,
credit card, and whatnot. You would simply also add a hidden field for
each Stooge to that form page. Apply the PHP Form Action to that page,
and you would be all set. Now, no matter how you process the form from
that point on, any purchases from the gallery page would be reflected
in the form that gets sent from the order page, because the Action
would “wire” those hidden form fields to have the same value as the
fields on the previous page. Imagine it as a sort of bucket brigade,
passing the output of the first page on to the third.
If you wanted to be more flexible about how many products you had to
offer, and didn’t want to have to constantly update the order form
page to have a hidden field for each item in your gallery, then you
could name all of the checkboxes on the gallery in this manner:
Then, on your order page, you would simply have a single hidden field
named ‘orders’. The first page would post an array containing the
images that were checked off, and the second page would send that
array along to the form processor. If you wanted to be really fancy,
you would calculate the price by checking the size of that array:
$total = round((count($_POST['items']) * 9.95), 2);
Back in your final form handler, you would parse out which pictures
were ordered by looking into that items array. So if they had ordered
Larry and Moe, the items form field would contain:
larry => 1,
moe => 1
//and you could make it a readable string thusly:
$order = implode(', ',array_keys($_POST['orders']));
//which outputs 'larry, moe'
I know I’ve dumped a bunch of stuff on you all at once, but this is a
pretty accessible thing to try out as a beginner to PHP. I recommend
you try to stumble through it, and see where you get. Post questions
(and preferably links to broken pages if you’re stuck) so we can pitch
in and help you get up that first rung of the ladder.
On Feb 1, 2009, at 1:32 PM, Philip Caplan wrote:
So, if you two can help me understand how to get the field content
from my “sort-of-gallery” page into a formfield on the next “place-
an-order” page, that would be wonderful!
freewaytalk mailing list
Update your subscriptions at: