Please help on a redirect problem

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
6ixty6
Forum Newbie
Posts: 4
Joined: Fri Jun 08, 2007 7:59 am

Please help on a redirect problem

Post by 6ixty6 »

Hi all

I have managed to drag my way through some tutorials and got myself a php emial form which only lets you send the info if the checkbox is ticked but if it isnt then an alert box appears.

Does anyone know how i can get my page to redirect back to where it was when the user clicks OK on the alert box because at the moment it goes to a blank page.

cheers and hopefully someone can help a newbie.

regards

Craig
Last edited by 6ixty6 on Sun Jun 24, 2007 10:08 am, edited 5 times in total.
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post by blackbeard »

Are you going to another page to process the form?

Post some code so we have an idea of what's going on?
6ixty6
Forum Newbie
Posts: 4
Joined: Fri Jun 08, 2007 7:59 am

hi

Post by 6ixty6 »

i will download the file tonight and post back tomorrow with the code its really just a auto redirect that i need nut reallly not sure what it would be.

cheers

craig
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

This is more of a client side question. At least I assume so when you use the term 'Alert Box'. If this is not, I will move it back to PHP Code, but for now I think it best to put it into Client Side.

Moved :arrow: Client Side
6ixty6
Forum Newbie
Posts: 4
Joined: Fri Jun 08, 2007 7:59 am

Alert box redirect command

Post by 6ixty6 »

Ok , I have downloaded my file and this is all the code in it.

Now all works fine, so when the checkbox is selected it then sends the emails and then the page redirects back to the form but if the checkbox isnt selected then it brings up the alert box but the form page goes to a blank page.

So what im trying to get is when the checkbox isnt selected then the alert box needs to pop up but when you select ok it should go back to the form.

cheers and hope someone can help

:lol:
Last edited by 6ixty6 on Sun Jun 24, 2007 10:13 am, edited 3 times in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Edit | Sorry, I just reread your question and I answered it wrong. Though this is good information, so I will leave it. :D

So right now if the box is checked it does what you want, but if the box is not checked it doesn't? Is that right?
==================================================
What you are after is capturing the page that the form was started on so that when the form is submitted the user is sent back to there they started.

That is easy to do, but you need to be able to snag the current pagename while you are on the way to the form (this can be done by passing a querystring var to the page called something like redirect):

Code: Select all

<?php
echo '<a href="formpage.php?redirect=' . basename(__FILE__) . '">Go to the form</a>';
?>
Then on the form page, have a hidden form field with the redirect page that is captured through the query string:

Code: Select all

<?php
// This should be validated, only use this as an example
$redirect = $_GET['redirect'];

// Form stuff here
echo '<input type="hidden" name="redirect" value="' . $redirect . '" />';
?>
Then, on the form processing page, when the data is validated and finally approved for sending, after the send, redirect using the redirect value:

Code: Select all

<?php
// This should also be validated, only use this as an example
$redirect = $_POST['redirect'];

// Form processing

// Cleared to go
header('Location: ' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_FILENAME'] . $redirect);
exit;
?>
Bear in mind that you should really be checking isset() or empty() on any data that could possibly not be set, like the $_GET and $_POST superglobals. But this should give you the general idea of what you want to accomplish.
6ixty6
Forum Newbie
Posts: 4
Joined: Fri Jun 08, 2007 7:59 am

Post by 6ixty6 »

So should i be putting all this into the same page with the form on becuase at the minute i have a newsletter.htm which has the form on it and when the submit button is clicked it goes to mainform.php then once the details have been sent it redirects back to newsletter.htm

but if the checkbox isnt selected it pops up an alert box and then when the ok button is clicked it makes the newsletter.htm goto a blank page.


Sorry but all this is a bit tricky for me to get.

Is there a way of showing some text that says "sorry check box must be selected to send form" instead of the alert box or something that is simpler??

:lol:
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Can you post the section of the Javascript code that redirects after the alert again?
Post Reply