View Full Version : Selecting Things Automatically In Form From Previous Page...

02-17-2008, 11:33 PM
Hi all I have a list of events on my web site, next to each one is an RSVP link... When the user clicks on 1 it takes them to a form to fill out, one of the fields is a drop down of all the events... I thought it would be cool though if the form has automatically selected the event from the user's RSVP click... Can this be handled by PHP or is it JavaScript?

02-18-2008, 04:00 AM
It could be either, because you can use cookies with both PHP and/or Javascripting.

The first form would go to a script that sets the cookie(s).
That script would redirect to the next form ... the user would
not see the "middle-man" where the cookie gets set because
it executes and re-directs. Pretty much the same thing as
a log-in script.

You could use the cookies to retain all of the 1st form variables.

Just remember that you can't set a cookie and use it in the same
script without a refresh in-between. It's that refresh (header) that
sets the cookie when the page is displayed. That is the purpose
for that script in-between.


All that being said (about cookies).... if your first form goes
directly to the next form, you really don't need to use cookies at all.
The 2nd form can read variables that get sent from the 1st one.

A good reason to use cookies: in case they finish the first form and
don't complete the 2nd form. You can detect that if they return to
your site and let them know that the form was only 1/2 finished.

You can also choose to give them the option to "retain their settings"
or not (by using cookies)... example: "remember me the next time".

02-18-2008, 09:27 PM
I thought it would be cool

Rather than it being cool, I'd suggest that this is a requirement. If I click on a link to identify what I want to RSVP for, I don't want to have select again what I'm RSVPing for.

You can do it with just PHP.

Form your link like this:


Then in rsvp.php, you'd read $_GET['event_id'] while looping through all the events and compare the ID. If they are equal, echo 'selected="selected"'.