This is a discussion on "form" within the PHP Forum section. This forum, and the thread "form are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
form
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
form
Hi Guys!
I have this phpfile which i use for a contact form. How can i redirect the visitor after submiting the form? Here is the php:
Last edited by karinne; Apr 3rd, 2007 at 14:00. Reason: Please use [php]...[/php] tags when displaying PHP code! |
|
|
|
||||
|
Re: form
Maybe somebody has an instant answer based on your post. I don't know of one.
This is a very simple problem but unfortunately, afaik, needs to be done in light of the entire framework of the form and form handler and the pages and file names involved. (The code you have given is the core of the form handler, btw.) You may not be able to actually redirect the user, which can be done only prior to any other browser output. My quick and dirty suggestion is to insert this line immediatly after "mail($to, $subject, $body);"
|
|
|||
|
Re: form
Thank you Mason i will try it def.
|
|
||||
|
Re: form
|
|
|||
|
Re: form
thanx Ryan! and where should i place it?
|
|
||||
|
Re: form
You have to place it before any content appears. For instance:
|
|
|||
|
Re: form
As above, if you're sending headers you need to do so before anything is echoed to the screen as that would automatically send the headers. Therefore either don't have any echoes in sections of your code that may then lead to a redirect, or use output buffering to make sure its not actually sent. Add exit; directly under your header call.
|
|
|||
|
Re: form
to make things simple i use a session trick
1) submit the form for the php processing file. 2) process the form 3) set sessions depending upon the outcome of the process ...... for example ::
On that destination page, test whether any of the sessions are set, and echo out the corresponding erros / confirmations etc. Just remember to kill the sessions when your done |
|
|||
|
Re: form
ohhhh....thanx guys! i will try it! i will come back if it doesnt work.
|
|
|||
|
Re: form
i have Mason's version which is works ok, but i dont realy get the rest of the tips guys as i dont know nothing about php.
|
|
||||
|
Re: form
There are actually a lot of things you can do in PHP that are a little slicker, but there is something to be said in terms of user psychology for a "Your message has been delivered" message with a "click to continue" link. Especially for people who are not totally adept at using the internet, it gives a feeling of security and control.
Anyway, if you are interested in something fancier, you'll need to post a little more info for us: Where is the form located, how do they get to it, and where do you want them to go after the submission? Actually, instead of redirecting the user back to his previous location, you might consider not making him leave the page in the first place. You can put the form as an include on the pages from which it is accessed and put the form handler right on the same page, as well. Instead of leaving the page, the form can be added to the page contents when a link is clicked, the success message can be added to the page when the form is submitted, and the user would never need to navigate out in the first place. Something like this (off the top of my head as an idea, there could easily be a bug or two). I'll do this so that the form appears right on the page, but all you have to do is relocate the code block and move the final bracket around to make the other content disappear:
If this is confusing, here's what I am thinking: 1) User gets a content page containing a link "contact us". 2) If the user clicks the link, the page changes so that the contact form appears. You have the option to display any, all, or none of the page content along with the form. 3) After the user has submits the form, he is still on the same page, only now there is a message "your data has been sent" or "something went wrong". Again, you have simple options. You can have the original page with the success message in it somewhere; you can have just the message and a link/button to click to redisplay the original page; or you can show a picture of Anna Nichole Smith's baby. I think this will access the cache, at least for the graphics; maybe someone with some knowledge in the area will tell us. If so, it should be as fast as the connection and server. With a good connection and the host server behaving, the page should barely blink. It's a poor man's AJAX -- in fact it is superior to AJAX for us non-guru types in one respect, i.e. the security is easier. Last edited by masonbarge; Apr 21st, 2007 at 16:13. |
|
|||
|
Re: form
Here is the link to the site which is still in developing. http://www.vinotrade.co.uk
|
|
||||
|
Re: form
Okay, I played with this and stuck it into a page I'm making. Here is what I came up with. It's just a skeleton template to change the display, with no transmission of the form data and no security. It can easily be improved (the code could use some touchup and the formatting needs work) but it works ok.
http://www.muggajo.com/SunriseCitrus/index.php#contact Use the big button in the center of the page -- the link in the footer will just get you an email form.
|
|
||||
|
Re: form
Quote:
I actually think the template I posted will work great on this. I actually like the way it's set up just fine, but it would be nice to have a little message confirming that a message has been sent. BTW you'll need a spam block on the message feature. And form validation -- this is like a sign "PLEASE HACK ME". Last edited by masonbarge; Apr 21st, 2007 at 18:18. |
|
||||
|
Re: form
i use a little window that does 2 things. 1. Tells user that form has been submitted. 2. When they click ok it redirects them to the page where the form was.
Here it is here: (in head tags)
|
|
|||
|
Re: form
That sounds good.And how can i use it with the code i have now? Should i just place this code to the head of the contact page? I dont realy know javascript either to be honest..
|
|
||||
|
Re: form
If you mean the code i posted yes, put it into the head tags. You can change the message to whatever you want, as you can see just now the message is "Thank You, Your Email Has Been Sent". And the direct page just now is ''contact_us.php'', change this to the page that you want the user to be re-directed too.
I hope that helps. |
![]() |
| Tags |
| form |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Hiding / Showing form fields based on previous form input | John Alexander Hopper | PHP Forum | 1 | Mar 10th, 2008 11:30 |
| form variable within an iframe component of a form | kissfreaque | PHP Forum | 3 | Feb 29th, 2008 13:06 |
| form variable within an iframe component of a form | kissfreaque | JavaScript Forum | 5 | Feb 29th, 2008 11:57 |
| [SOLVED] PHP contact form redirect to same form | Posie | PHP Forum | 14 | Jan 29th, 2008 20:28 |
| ASP form to check weather a form value is already in the database | Andrew1986 | Classic ASP | 3 | Oct 25th, 2007 08:23 |