PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 4th, 2013, 06:39 AM
Frankie78 Frankie78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 9 Frankie78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 51 m 56 sec
Reputation Power: 0
PHP Form Validation Redirect Issue

Hello,

I'm not sure what I'm doing wrong here. The goal here is to validate my form and when it's successful the email is sent and the user is redirected. However, when the PHP form is loaded, you're instantly redirected and the form is not loaded.

PHP Code:
<?php

$emailSubject 
'Blah Blah';
$webMaster 'email address';
$headers "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";

$name $_POST['name'];
$email $_POST['email'];
$phone $_POST['phone'];
$domain $_POST['domain'];
$start_time $_POST['start_time'];
$message $_POST['message'];

$nameErr "";
$emailErr "";
$phoneErr "";
$messageErr "";

$body = <<<EOD
<b>Contact Info</b>
<hr>
Name: 
$name<br>
Phone: 
$phone<br>
Email: 
$email<br>
<br>
<b>Project Info</b>
<hr>
Domain Name Needed? 
$domain<br>
Project Start Time: 
$start_time<br>
Details: 
$message<br>
EOD;

if(isset(
$_POST['submit'])) {
    
    if (empty(
$_POST["name"])) {
        
$nameErr "This field is required.";
    }
    else {
        
$name $_POST["name"];
    }
    
    if (empty(
$_POST["email"])) {
        
$emailErr "This field is required.";
    }
    else if(
filter_var($emailFILTER_VALIDATE_EMAIL) == FALSE){
        
$emailErr "Please specify a valid email address.";
    }
    else {
        
$email $_POST["email"];
    }

    if (empty(
$_POST["phone"])) {
        
$phoneErr "This field is required.";
    }
    else if(!
preg_match("/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/"$phone)){
        
$phoneErr "Please specify a valid phone number.";
    }
    else {
        
$phone $_POST["phone"];
    }
    
    if (empty(
$_POST["message"])) {
        
$messageErr "This field is required.";
    }
    else {
        
$message $_POST["message"];
    }
}

mail($webMaster$emailSubject$body$headers);
header"Location: (URL)" );

?>

Reply With Quote
  #2  
Old January 4th, 2013, 07:00 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 1 h 48 m 27 sec
Reputation Power: 581
Please edit your post and fix the tags ([ PHP ] not [PHPNET]). It is very hard to read but it appears to me that the mail and header calls are misplaced. They probably need to be inside the 'if' block. They currently appear to be executed whether the form is submitted or not.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old January 4th, 2013, 07:25 AM
Frankie78 Frankie78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 9 Frankie78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 51 m 56 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
Please edit your post and fix the tags ([ PHP ] not [PHPNET]). It is very hard to read but it appears to me that the mail and header calls are misplaced. They probably need to be inside the 'if' block. They currently appear to be executed whether the form is submitted or not.


Fixed the tags. Could you elaborate a bit on your response please. Thank you.

Reply With Quote
  #4  
Old January 4th, 2013, 07:43 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 1 h 48 m 27 sec
Reputation Power: 581
Now that I can read your code more easily, it is behaving exactly as you programmed it. The first time the page is displayed, $_POST['Submit'] is not set so it skips all the code except for the 'mail' and 'header' calls. That is why it immediately displays the redirection page. You need to simply move the last '}' after those calls.

Reply With Quote
  #5  
Old January 4th, 2013, 09:26 AM
Frankie78 Frankie78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 9 Frankie78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 51 m 56 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
Now that I can read your code more easily, it is behaving exactly as you programmed it. The first time the page is displayed, $_POST['Submit'] is not set so it skips all the code except for the 'mail' and 'header' calls. That is why it immediately displays the redirection page. You need to simply move the last '}' after those calls.


I moved

PHP Code:
 mail($webMaster$emailSubject$body$headers); 
header"Location: (URL)" ); 


into the last '}' and I still get the same results. It redirects as soon as I hit the page.

Reply With Quote
  #6  
Old January 4th, 2013, 09:41 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 1 h 48 m 27 sec
Reputation Power: 581
Not possible if you did what I said. Re-post all your code as there must be something else you are not showing.

Reply With Quote
  #7  
Old January 4th, 2013, 10:17 AM
Frankie78 Frankie78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 9 Frankie78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 51 m 56 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
Not possible if you did what I said. Re-post all your code as there must be something else you are not showing.


This is what I have...

PHP Code:
<?
$emailSubject 
'blah blah';
$webMaster 'email address';
$headers "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";

$name $_POST['name'];
$email $_POST['email'];
$phone $_POST['phone'];
$domain $_POST['domain'];
$start_time $_POST['start_time'];
$message $_POST['message'];

$nameErr "";
$emailErr "";
$phoneErr "";
$messageErr "";

$body = <<<EOD
<b>Contact Info</b>
<hr>
Name: 
$name<br>
Phone: 
$phone<br>
Email: 
$email<br>
<br>
<b>Project Info</b>
<hr>
Domain Name Needed? 
$domain<br>
Project Start Time: 
$start_time<br>
Details: 
$message<br>
EOD;

if(isset(
$_POST['submit'])) {
    
    if (empty(
$_POST["name"])) {
        
$nameErr "This field is required.";
    }
    else {
        
$name $_POST["name"];
    }
    
    if (empty(
$_POST["email"])) {
        
$emailErr "This field is required.";
    }
    else if(
filter_var($emailFILTER_VALIDATE_EMAIL) == FALSE){
        
$emailErr "Please specify a valid email address.";
    }
    else {
        
$email $_POST["email"];
    }

    if (empty(
$_POST["phone"])) {
        
$phoneErr "This field is required.";
    }
    else if(!
preg_match("/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/"$phone)){
        
$phoneErr "Please specify a valid phone number.";
    }
    else {
        
$phone $_POST["phone"];
    }
    
    if (empty(
$_POST["message"])) {
        
$messageErr "This field is required.";
    }
    else {
        
$message $_POST["message"];
    }
mail($webMaster$emailSubject$body$headers);
header"Location: URL");
}
?>

Reply With Quote
  #8  
Old January 4th, 2013, 10:32 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 1 h 48 m 27 sec
Reputation Power: 581
As far as I can tell that will do absolutely nothing. Since there is no form the code can never be executed.

Reply With Quote
  #9  
Old January 4th, 2013, 10:58 AM
Frankie78 Frankie78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 9 Frankie78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 51 m 56 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
As far as I can tell that will do absolutely nothing. Since there is no form the code can never be executed.


Here's the form:

Code:
<?php
   include('validate.php');
?>
<html>
<body>
<form id="form" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<fieldset>
  <legend>Contact Info</legend>
  <label>Your Name<span class="red">*</span></label>
  <input type="text" name="name" id="name" class="required   letters" value="<?php echo htmlspecialchars($name); ?>"/>
   <label class="error"><?php echo $nameErr; ?></label>

   <label>Email<span class="red">*</span></label>
   <input type="text" name="email" id="email" class="required  email" value="<?php echo ($email); ?>" />
   <label class="error"><?php echo $emailErr; ?></label>
					
   <label>Phone<span class="red">*</span></label>
   <input type="text" name="phone" id="phone" class="required phoneUS" value="<?php echo htmlspecialchars($phone); ?>"/>
   <label class="error"><?php echo $phoneErr; ?></label>
</fieldset>
<fieldset>
   <legend>Project Details</legend>
   <label>Need a Domain Name?</label>
   <input type="radio" id="radio" name="domain" value="No"/><span class="style1">No</span>
   <input type="radio" id="radio" name="domain" value="Yes"/><span class="style1">Yes</span>
   <input type="radio" id="radio" name="domain" value="Not Sure" /><span class="style1">Not Sure</span>
   
   <label>If No, Current Domain Name?</label>
   <input type="text" name="url" value="http://"/>
   
   <label>Project Start Time</label>
   <input type="radio" id="radio" name="start_time" value="1-2 Weeks"/><span class="style1">1-2 Weeks</span>
   <input type="radio" id="radio" name="start_time" value="3-4 Weeks"/><span class="style1">3-4 Weeks</span>
   <input type="radio" id="radio" name="start_time" value="1 Month+"/><span class="style1">1 Month+</span>
   <input type="radio" id="radio" name="start_time" value="Not Sure" checked="checked"/><span class="style1">Not Sure</span>

   <label>Project Description<span class="red">*</span></label>
   <textarea name="message" id="message" class="required"><?php echo htmlspecialchars($message); ?></textarea>
   <label class="error"><?php echo $messageErr; ?></label>
   <label class="style"><span class="red">*</span> Required Fields</label>
</fieldset>
<input type="submit" id="submit" name="submit" class="submit" value="Submit" />

</form>
</body>
</html>

Reply With Quote
  #10  
Old January 4th, 2013, 11:17 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 1 h 48 m 27 sec
Reputation Power: 581
Do I assume that 'validate.php' contains the code you posted? If so you need to move the 'if (isset' to surround the include and don't use it in the php file itself. In other words only execute the include if the form has been submitted and in that PHP file assume that it is only executed if the form has been submitted.
PHP Code:
<?php
if (isset($_POST['submit'])) {
   include(
'validate.php');
}
?>

Reply With Quote
  #11  
Old January 4th, 2013, 11:35 AM
Frankie78 Frankie78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 9 Frankie78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 51 m 56 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
Do I assume that 'validate.php' contains the code you posted? If so you need to move the 'if (isset' to surround the include and don't use it in the php file itself. In other words only execute the include if the form has been submitted and in that PHP file assume that it is only executed if the form has been submitted.
PHP Code:
<?php
if (isset($_POST['submit'])) {
   include(
'validate.php');
}
?>


Curious to know where I would place the redirect script.

Reply With Quote
  #12  
Old January 4th, 2013, 12:09 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 1 h 48 m 27 sec
Reputation Power: 581
I thought it was already in 'validate.php'. If not then you have still not posted all the requisite code.

Reply With Quote
  #13  
Old January 4th, 2013, 04:10 PM
Frankie78 Frankie78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 9 Frankie78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 51 m 56 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
I thought it was already in 'validate.php'. If not then you have still not posted all the requisite code.


This is my 'validate.php' and the redirect script is at the very bottom:

PHP Code:
<?php 

$emailSubject 
'Blah Blah'
$webMaster 'email address'
$headers "From: $email\r\n"
$headers .= "Content-type: text/html\r\n"

$name $_POST['name']; 
$email $_POST['email']; 
$phone $_POST['phone']; 
$domain $_POST['domain']; 
$start_time $_POST['start_time']; 
$message $_POST['message']; 

$nameErr ""
$emailErr ""
$phoneErr ""
$messageErr ""

$body = <<<EOD 
<b>Contact Info</b
<
hr
Name$name<br
Phone$phone<br
Email$email<br
<
br
<
b>Project Info</b
<
hr
Domain Name Needed$domain<br
Project Start Time$start_time<br
Details$message<br
EOD

if(isset(
$_POST['submit'])) { 
     
    if (empty(
$_POST["name"])) { 
        
$nameErr "This field is required."
    } 
    else { 
        
$name $_POST["name"]; 
    } 
     
    if (empty(
$_POST["email"])) { 
        
$emailErr "This field is required."
    } 
    else if(
filter_var($emailFILTER_VALIDATE_EMAIL) == FALSE){ 
        
$emailErr "Please specify a valid email address."
    } 
    else { 
        
$email $_POST["email"]; 
    } 

    if (empty(
$_POST["phone"])) { 
        
$phoneErr "This field is required."
    } 
    else if(!
preg_match("/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/"$phone)){ 
        
$phoneErr "Please specify a valid phone number."
    } 
    else { 
        
$phone $_POST["phone"]; 
    } 
     
    if (empty(
$_POST["message"])) { 
        
$messageErr "This field is required."
    } 
    else { 
        
$message $_POST["message"]; 
    } 


mail($webMaster$emailSubject$body$headers); 
header"Location: (URL)" ); 

?>

Reply With Quote
  #14  
Old January 4th, 2013, 04:25 PM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,879 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 2 Weeks 2 Days 1 h 48 m 27 sec
Reputation Power: 581
First, if you put the 'if' I suggested around the include then you no longer need it in 'validate.php'.
PHP Code:
<?php 

$emailSubject 
'Blah Blah'
$webMaster 'email address'
$headers "From: $email\r\n"
$headers .= "Content-type: text/html\r\n"

$name $_POST['name']; 
$email $_POST['email']; 
$phone $_POST['phone']; 
$domain $_POST['domain']; 
$start_time $_POST['start_time']; 
$message $_POST['message']; 

$nameErr ""
$emailErr ""
$phoneErr ""
$messageErr ""

$body = <<<EOD 
<b>Contact Info</b
<
hr
Name$name<br
Phone$phone<br
Email$email<br
<
br
<
b>Project Info</b
<
hr
Domain Name Needed$domain<br
Project Start Time$start_time<br
Details$message<br
EOD

if (empty(
$_POST["name"])) { 
     
$nameErr "This field is required."

else { 
     
$name $_POST["name"]; 

     
 if (empty(
$_POST["email"])) { 
      
$emailErr "This field is required."

else if(
filter_var($emailFILTER_VALIDATE_EMAIL) == FALSE){ 
     
$emailErr "Please specify a valid email address."

else { 
   
$email $_POST["email"]; 


if (empty(
$_POST["phone"])) { 
    
$phoneErr "This field is required."

else if(!
preg_match("/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/"$phone)){ 
   
$phoneErr "Please specify a valid phone number."

else { 
    
$phone $_POST["phone"]; 

     
if (empty(
$_POST["message"])) { 
    
$messageErr "This field is required."

else { 
    
$message $_POST["message"]; 


mail($webMaster$emailSubject$body$headers); 
header"Location: (URL)" ); 

?>

Second, I don't understand your question about where to put the redirect. You already have it in 'validate.php'.

Reply With Quote
  #15  
Old January 4th, 2013, 04:44 PM
Frankie78 Frankie78 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 9 Frankie78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 51 m 56 sec
Reputation Power: 0
Quote:
Originally Posted by gw1500se
First, if you put the 'if' I suggested around the include then you no longer need it in 'validate.php'.
PHP Code:
<?php 

$emailSubject 
'Blah Blah'
$webMaster 'email address'
$headers "From: $email\r\n"
$headers .= "Content-type: text/html\r\n"

$name $_POST['name']; 
$email $_POST['email']; 
$phone $_POST['phone']; 
$domain $_POST['domain']; 
$start_time $_POST['start_time']; 
$message $_POST['message']; 

$nameErr ""
$emailErr ""
$phoneErr ""
$messageErr ""

$body = <<<EOD 
<b>Contact Info</b
<
hr
Name$name<br
Phone$phone<br
Email$email<br
<
br
<
b>Project Info</b
<
hr
Domain Name Needed$domain<br
Project Start Time$start_time<br
Details$message<br
EOD

if (empty(
$_POST["name"])) { 
     
$nameErr "This field is required."

else { 
     
$name $_POST["name"]; 

     
 if (empty(
$_POST["email"])) { 
      
$emailErr "This field is required."

else if(
filter_var($emailFILTER_VALIDATE_EMAIL) == FALSE){ 
     
$emailErr "Please specify a valid email address."

else { 
   
$email $_POST["email"]; 


if (empty(
$_POST["phone"])) { 
    
$phoneErr "This field is required."

else if(!
preg_match("/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/"$phone)){ 
   
$phoneErr "Please specify a valid phone number."

else { 
    
$phone $_POST["phone"]; 

     
if (empty(
$_POST["message"])) { 
    
$messageErr "This field is required."

else { 
    
$message $_POST["message"]; 


mail($webMaster$emailSubject$body$headers); 
header"Location: (URL)" ); 

?>

Second, I don't understand your question about where to put the redirect. You already have it in 'validate.php'.


The problem originally was that when the script executes it redirects without performing the validation. I've tried numerous things and still no good.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP Form Validation Redirect Issue

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap