Please help on a redirect problem
Moderator: General Moderators
Please help on a redirect problem
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
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
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Alert box redirect command
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

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
Last edited by 6ixty6 on Sun Jun 24, 2007 10:13 am, edited 3 times in total.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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):
Then on the form page, have a hidden form field with the redirect page that is captured through the query string:
Then, on the form processing page, when the data is validated and finally approved for sending, after the send, redirect using the redirect value:
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.
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>';
?>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 . '" />';
?>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;
?>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??

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??
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA