Page 1 of 1
Please help on a redirect problem
Posted: Fri Jun 08, 2007 8:02 am
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
Posted: Fri Jun 08, 2007 11:28 am
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?
hi
Posted: Fri Jun 08, 2007 11:45 am
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
Posted: Fri Jun 08, 2007 11:51 am
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

Client Side
Alert box redirect command
Posted: Mon Jun 11, 2007 9:39 am
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

Posted: Mon Jun 11, 2007 10:43 am
by RobertGonzalez
Edit | Sorry, I just reread your question and I answered it wrong. Though this is good information, so I will leave it.
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.
Posted: Tue Jun 12, 2007 8:52 am
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??

Posted: Tue Jun 12, 2007 10:07 am
by RobertGonzalez
Can you post the section of the Javascript code that redirects after the alert again?