Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 1105 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Php contact form question

Thread title: Php contact form question
Reply    
    Thread tools Search this thread Display Modes  
01-28-2011, 07:09 AM
#1
lplplpx3 is offline lplplpx3
Status: I'm new around here
Join date: Mar 2010
Location:
Expertise:
Software:
 
Posts: 5
iTrader: 0 / 0%
 

lplplpx3 is on a distinguished road

  Old  Php contact form question

This code is from the bottom of a php contact submission form. How can I change the code to direct to, or display a specified web page if the email was successful and another if not in order to stop this generic page from showing. Thanks.

<?php if(isset($emailSent) == true) { ?>
<div class="ok">
<h1>Thanks, <?php echo $name;?></h1>
<p>Your email was successfully sent. We will be in touch soon.</p>
</div>
<?php } ?>


<?php if(isset($hasError) ) { ?>
<div class="error2">There was an error submitting the form.</div>
<?php } ?>

01-28-2011, 07:24 AM
#2
Psychotomus is offline Psychotomus
Status: Member
Join date: Mar 2005
Location: baltimore, md, usa
Expertise: php, mySQL, js, aJax
Software: virtual brain cells
 
Posts: 167
iTrader: 0 / 0%
 

Psychotomus is on a distinguished road

  Old

To redirect you would use

PHP Code:
header("Location: url"); 
You will not be able to redirect if you allready outputted text.

You can include another file by

PHP Code:
include("filepath/filename.ext"); 

01-28-2011, 07:40 AM
#3
lplplpx3 is offline lplplpx3
Status: I'm new around here
Join date: Mar 2010
Location:
Expertise:
Software:
 
Posts: 5
iTrader: 0 / 0%
 

lplplpx3 is on a distinguished road

  Old

Great. Thanks.

Reply With Quote
01-28-2011, 03:59 PM
#4
derek lapp is offline derek lapp
Status: design rockstar
Join date: Jan 2005
Location: guelph, ontario
Expertise:
Software:
 
Posts: 2,246
iTrader: 0 / 0%
 

derek lapp is on a distinguished road

  Old

Originally Posted by lplplpx3 View Post
This code is from the bottom of a php contact submission form. How can I change the code to direct to, or display a specified web page if the email was successful and another if not in order to stop this generic page from showing. Thanks.

<?php if(isset($emailSent) == true) { ?>
<div class="ok">
<h1>Thanks, <?php echo $name;?></h1>
<p>Your email was successfully sent. We will be in touch soon.</p>
</div>
<?php } ?>


<?php if(isset($hasError) ) { ?>
<div class="error2">There was an error submitting the form.</div>
<?php } ?>
using a header re-direct is useless here: the script itself has already done the success/fail check and given you conditions for each. just read through the code piece by piece.

the top chunk is what happens upon successful completion. the second chunk is what happens if an error is thrown. if you want to change what gets outup, just change the html betwene the <?php ?> tags:

Code:
<?php if(isset($emailSent) == true) { ?>
<!-- giant thank you graphic -->
<img src="images/thanks.jpg" alt="Thank you for your submission" />
<?php } ?>

<?php if(isset($hasError) ) { ?>
<!-- error was thrown -->
<img src="images/error.jpg" alt="stimpy, you iiidiot!" />
<?php } ?>

04-24-2011, 12:41 PM
#5
andrewsuzuki is offline andrewsuzuki
Status: I'm new around here
Join date: Apr 2011
Location: Connecticut, United States
Expertise: design/development
Software: Coda, Photoshop
 
Posts: 6
iTrader: 0 / 0%
 

andrewsuzuki is on a distinguished road

  Old

I would advise against using multiple pages for a contact form.
The best way is to have the processing and the HTML form on the same page, with the processing before you even echo the <html> tag. As long as you haven't echoed any html yet, you should be able to use the header() function. If you have echoed html, then you can use a meta redirect.

Reply With Quote
04-24-2011, 01:59 PM
#6
Gaz is offline Gaz
Gaz's Avatar
Status: Request a custom title
Join date: Apr 2007
Location: UK
Expertise: Code & Programming
Software: Coda, TextMate, Sublime 2
 
Posts: 2,097
iTrader: 26 / 100%
 

Gaz will become famous soon enough Gaz will become famous soon enough

Send a message via Skype™ to Gaz

  Old

Originally Posted by andrewsuzuki View Post
I would advise against using multiple pages for a contact form.

Why? There's no real reason not to..

You could use the action parameter of the form to send the POST data to another php file, which can then display different content based on the success or failure of the emailing. This would only require one extra file and keeps it somewhat modular.

Reply With Quote
04-24-2011, 11:24 PM
#7
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

Originally Posted by andrewsuzuki View Post
I would advise against using multiple pages for a contact form.
It all depends on the application, there is no reason why it would be "better" to use one page opposed to multiple. There have been some projects I've done where a single page was the best options but there have been others where a redirect was the best way to go. It doesn't really matter which one you do.

Reply With Quote
05-06-2011, 05:30 AM
#8
linkbuilding5 is offline linkbuilding5
Status: I'm new around here
Join date: Apr 2011
Location:
Expertise:
Software:
 
Posts: 16
iTrader: 0 / 0%
 

linkbuilding5 is on a distinguished road

  Old

You have to add just one line code after this line
<p>Your email was successfully sent. We will be in touch soon.</p>
header('Location: thanks.php');
exit();

Reply With Quote
07-24-2011, 02:16 AM
#9
infotechnologist is offline infotechnologist
Status: I'm new around here
Join date: Jul 2011
Location: USA
Expertise: Programming, Other IT Services
Software:
 
Posts: 3
iTrader: 0 / 0%
 

infotechnologist is on a distinguished road

  Old

I agree, there is no difference between one page, and using multiple. Some high end frameworks are built on the premise of splitting pages.

Reply With Quote
Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed