PDA

View Full Version : Show region if url parameter exists


Right-Click IT
03-21-2010, 12:09 PM
Hi, I would like to show an area on my page if a parameter exists in the address bar, and hide another area.

I have an enquiry form on the index.php page, and when the form is submitted, it submits to the same page (index.php) and universal email sends the contents of the form to an email address.

I dont want to create a thankyou.php page, but instead show a thankyou region and hide the form once submitted.

My url would show something like:

http://www.mywebsite.com/?ref=thankyou

Then the div containing the form elements would be hidden, and the div containing the thank you message would be displayed.

Is this possible?

Thanks

Lee

Jimmy Wu
03-22-2010, 12:02 PM
Yes, you would want to add a couple of php blocks around the code you want to have conditionally show:
<?php if (isset($_REQUEST["ref"])) { ?>
<p>your code</p>
<?php } ?>

Then you would want to use the isset function to check if the variable is set or not to determine if you want to show the code or not.

Right-Click IT
03-22-2010, 04:07 PM
Thanks Jimmy, so... if I have the index page containing the form and universal email goes to the same page (index.php?ref=thankyou) how do I hide the form and show the thank you confirmation?

For instance:

Here is the show if section of the page: (Upon successful submission of the form)

<?php if (isset($_REQUEST["ref"])) { ?>
<h2>Thank You!</h2>
<p>Thank you for submitting your Mortgage Enquiry search.</p>
<p>We will be in contact with you shortly.</p>
<?php } ?>

How do I then hide the form below it?

Thanks

Lee

Eric Mittman
03-23-2010, 09:02 AM
You can show an alternate message or area of the page with your if statement by adding in an else like this:


<?php if (isset($_REQUEST["ref"])) { ?>
<h2>Thank You!</h2>
<p>Thank you for submitting your Mortgage Enquiry search.</p>
<p>We will be in contact with you shortly.</p>
<?php } else { ?>
the form goes here
<?php } ?>


This will show either the thank you message or the form, but not both.

Eric Mittman
03-24-2010, 01:30 PM
Here is also a link to a thread where a user had a similar issue that and how they solved it:

http://www.webassist.com/forums/showthread.php?p=51141#post51141