PHP redirect and js function (after contact form processing)- help appreciated.

I have next to no PHP knowledge (and not much js knowledge for that matter!) - I write html and css and normally out source php work, but this should be easy and there is still a recession on! :smiley:

I have a small site for a client that is actually one html page with the various content as slides on a carousel via jQuery.

There s a contact form that is validated via jQuery and then a php file is run to process the form and send an email to the client. This all works. Normally I would re-direct to a dedicated thank you page with…
[php]$URL=“http://www.examplesite.com/”;
header (“Location: $URL”); [/php]

This works with the site in question at the moment, but simply resets the ‘slides’ to the first slide. I would like to trigger an link that would activate the “thank you” slide in the carousel. Something along the lines of…

<script type="text/javascript">$(#thankyou_qlink).click();</script>

Is there a way of the php re-directing back to the site and then triggering the correct slide? I’ve tried the following as a wild and uneducated stab in the dark!!..

[php]$URL=“http://www.shaunbrownbuilder.com/”;
header (“Location: $URL”);
echo ‘’;[/php]

Any help / advice would be much appreciated. Thank you.

Well, you could just add an “argument” to the URL. Arguments are added like this: www.domain.com/somepage.com?somevariablename=somevalue

So, you could do this:
$URL=“http://www.shaunbrownbuilder.com/index.php?thankyou=1”;
header (“Location: $URL”);

Then, inside your index.php page, you would use $_GET[‘thankyou’] to retrieve the variable’s value.
If it is ‘1’, then show your thankyou slide… If not equal to ‘1’, then do whatever you normally do…

This way would work, but, you would have to alter the default page that is at the root of your site.
(www.shaunbrownbuilder.com) Usually this is index.html or index.php. You can set that filename in your
sites config area. So, your site’s default page starts showing some slide, we assume. This code would
have to be changed to use a variable at where to start. That would be selected by the argument.

Did that make sense? Hope so… Good luck with it…

PS: you could also do this with a session variable if you do not want the user to see the argument in the
address bar’s name.

Thanks for your help. (the clients site has just gone live, currently without the thankyou slide. If you are interested to see the actual application).

The site is a single html page I’m guessing it would need to be a php page to run the variable? I’m pretty wet behind the ears when it comes to php!

I’m also a bit of a stickler for neat urls where possible (for SEO and user readability) - how would the “session variable” method work, that you mention? So that the argument is not displayed.

Thanks again for your time.

I too enjoy a clean address without variables…

So, first, YES, all pages that process PHP code need to be PHP pages, not HTML. Basically, just change the HTML to PHP.

Next, SESSION variables are similar to argument variables , but then are unseen… A session is created when you use PHP. It is useable in your code by adding this line to the first part of every page that uses session variables:

session_start();

This line is usually at the top of each page. Think of session variables as just a PHP array. It is available until the session variable are deleted using “unset[]” or until the browser is closed. Then, they go away. So, you can not keep info in them permanently.

To set a session variable, do it the same as an PHP array. Let’s say we create a variable to use as a session variable and we call it “thankyou”. You would set that variable in this manor:

$_SESSION[‘thankyou’] = “some-value-that-means-something-to-you!”;

You can create any name and value. It can even be another array. This info is passed onto ALL of your pages and can be read, altered or deleted as you need to. So, in your small photo example, you could set the value to something like “YES”, meaning yes, show the thank-you slide. If the value is not “YES”, then it would just show the other slides in the bunch… You could test this value in this manor:

if($_SESSION[‘thankyou’]==“YES”]){
//do some code for value of YES…
}else{
//do some other code for value NOT-YES…
}

So, if you want to show the thank-you slide one time, in your code for handling the yes, you would then also set the session variable to “NO” so that the slide is shown only one time. It if very versatile. Since the session variables are hidden from view, you can pass anything you wish inside of them. I use them all the time for USERID’s and UserNames. When a user log’s in, I save their user id in the session variables and display them on every page in a small area which may say "logged in as: " . $_SESSION[‘userid’]; In that way each page
is a bit personal and it looks nice. So, I think that might work well for you. Good luck!

This sounds ideal. (and very versatile for various other functions on sites I am designing at the moment).

Busy weeks ahead - so won’t get to have play with this until after then. But I’ll post on this thread when I have had a go at implementing it (and if I run into any issues :D).

Thanks again.

No problem! Take your time… Below is a link to a couple of sites that talk about SESSION variables in case it might give you further info. I notice I added an extra ‘]’ in my sample code… Hope that didn’t mess you up!
Good luck with your project… CYA in the bitstream…

http://www.tizag.com/phpT/phpsessions.php

http://php.net/manual/en/function.session-start.php

http://php.about.com/od/advancedphp/ss/php_sessions.htm

Sponsor our Newsletter | Privacy Policy | Terms of Service