Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    Regular Coder
    Join Date
    Aug 2009
    Posts
    160
    Thanks
    42
    Thanked 2 Times in 2 Posts

    2 unique forms on 1 page

    Ok, so I'm needing a basic "contact" form and a "services needed" form, on the same page...I can get them both to send/validate on separate pages, but I can't for the life of me get the forms to validate/send *separately*.

    I ran across an archived post from here @ CodingFourms that mentioned adding the hidden input and "if ( $_POST['formID']..." statements, but I've got something wrong somewhere.

    Code:
    <?php
    
    if ( $_POST['formID'] == 'contact') {
    
    define("EMAIL", "contact@southlakeradiology.com");
    
    if(isset($_POST['submit'])) {
     
      include('validate.class.php');
     
      //assign post data to variables
      $name = trim($_POST['name']);
        $email = trim($_POST['email']);
    	$message = trim($_POST['message']);
    	
     
      //start validating our form
      $v = new validate();
      $v->validateStr($name, "name", 3, 75);
      $v->validateEmail($email, "email");
      $v->validateStr($message, "message", 5, 1000); 
     
      if(!$v->hasErrors()) {
            $header = "From: $email\n" . "Reply-To: $email\n";
            $subject = "Form Submission";
            $email_to = EMAIL;
     
            $emailMessage = "Name: " . $name . "\n";
            $emailMessage .= "Email: " . $email . "\n";
            $emailMessage .= $message;
     
        //use php's mail function to send the email
            @mail($email_to, $subject ,$emailMessage ,$header ); 
     
        //grab the current url, append ?sent=yes to it and then redirect to that url
            $url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
            header('Location: '.$url."?sent=yes");
     
        } else {
        //set the number of errors message
        $message_text = $v->errorNumMessage();      
     
        //store the errors list in a variable
        $errors = $v->displayErrors();
     
        //get the individual error messages
        $nameErr = $v->getError("name");
        $emailErr = $v->getError("email");
        $messageErr = $v->getError("message");
      }//end error check
    }// end isset
    }
    
    if ( $_POST['formID'] == 'services') {
    define("EMAIL", "contact@southlakeradiology.com");
    
    if(isset($_POST['submit'])) {
     
      include('validate.class.php');
     
      //assign post data to variables
      $name = trim($_POST['name']);
        $email = trim($_POST['email']);
    	$phone = trim($_POST['phone']);
    	$location = trim($_POST['location']);
    	$value1 = trim($_POST['value1']);
    	$value2 = trim($_POST['value2']);
    	$value3 = trim($_POST['value3']);
    	$value4 = trim($_POST['value4']);
    	$message = trim($_POST['message']);
    	
     
      //start validating our form
      $v = new validate();
      $v->validateStr($name, "name", 3, 75);
      $v->validateEmail($email, "email");
      $v->validateStr($phone, "phone", 3, 75);
      $v->validateStr($location, "location", 3, 75);
      $v->validateStr($message, "message", 5, 1000); 
     
      if(!$v->hasErrors()) {
            $header = "From: $email\n" . "Reply-To: $email\n";
            $subject = "Form Submission";
            $email_to = EMAIL;
     
            $emailMessage = "Name: " . $name . "\n";
            $emailMessage .= "Email: " . $email . "\n";
    		$emailMessage .= "Phone: " . $phone . "\n";
            $emailMessage .= "Location: " . $location . "\n";
            $emailMessage .= "Value1: " . $email . "\n";
    		$emailMessage .= "Value2: " . $email . "\n";
    		$emailMessage .= "Value3: " . $email . "\n";
    		$emailMessage .= "Value4: " . $email . "\n";		
            $emailMessage .= $message;
     
        //use php's mail function to send the email
            @mail($email_to, $subject ,$emailMessage ,$header ); 
     
        //grab the current url, append ?sent=yes to it and then redirect to that url
            $url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
            header('Location: '.$url."?sent=yes");
     
        } else {
        //set the number of errors message
        $message_text = $v->errorNumMessage();      
     
        //store the errors list in a variable
        $errors = $v->displayErrors();
     
        //get the individual error messages
        $nameErr = $v->getError("name");
        $emailErr = $v->getError("email");
    	$phoneErr = $v->getError("phone");
        $locationErr = $v->getError("location");
        $messageErr = $v->getError("message");
      }//end error check
    }// end isset
    }
    ?>
    
    <?php include 'header.php'; ?>
    <!--content starts below here-->
    ********UNDER CONSTRUCTION********
    <p class="contact"><span>Toll Free Numbers:</span>&nbsp;Office (866) 333-8443 or Fax (866) 316-0080
    </p>
      <p class="contact"><span>Questions and/or Comments:</span>
    </p>
    
    <div id="contact_form_wrap">
        <span class="message"><?php echo $message_text; ?></span>
        <?php echo $errors; ?>
        <?php if(isset($_GET['sent'])): ?><span class="sent">Your message has been sent</span><?php endif; ?>
        <form id="contact_form" method="post" action="contact.php"><input type="hidden" name="formID"
    value="contact">
          <p><label>Name:<br />
          <input type="text" name="name" class="textfield" title="name" value="<?php echo htmlentities($name); ?>" />
          </label><br /><span class="errors"><?php echo $nameErr; ?></span></p>
     
          <p><label>Email: <br />
          <input type="text" name="email" class="textfield" title="email" value="<?php echo htmlentities($email); ?>" />
          </label><br /><span class="errors"><?php echo $emailErr ?></span></p>         
     
          <p><label>Message: <br />
          <textarea name="message" class="textarea" title="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
          </label><br /><span class="errors"><?php echo $messageErr ?></span></p>
     
          <p><input type="submit" name="submit" class="button" value="Submit" /><input type="reset" name="reset" class="button" value="Reset" /></p></form>
      </div>
    
    <p class="contact"><span>Radiology Needs:</span>
    </p>
      <div id="contact_form_wrap">
        <span class="message"><?php echo $message_text; ?></span>
        <?php echo $errors; ?>
        <?php if(isset($_GET['sent'])): ?><span class="sent">Your message has been sent</span><?php endif; ?>
        <form id="services_form" method="post" action="contact.php"><input type="hidden" name="formID"
    value="services">
          <p><label>Name:<br />
          <input type="text" name="name" class="textfield" title="name" value="<?php echo htmlentities($name); ?>" />
          </label><br /><span class="errors"><?php echo $nameErr; ?></span></p>
     
          <p><label>Email: <br />
          <input type="text" name="email" class="textfield" title="email" value="<?php echo htmlentities($email); ?>" />
          </label><br /><span class="errors"><?php echo $emailErr ?></span></p>        
    	  
    	  <p><label>Phone: <br />
          <input type="text" name="phone" class="textfield" title="phone" value="<?php echo htmlentities($phone); ?>" />
          </label><br /><span class="errors"><?php echo $phoneErr ?></span></p>  
     
           <p><label>Location For Requested Services: <br />
          <input type="text" name="location" class="textfield" title="location" value="<?php echo htmlentities($location); ?>" />
          </label><br /><span class="errors"><?php echo $locationErr ?></span></p>
     
           <div class="clearfix">
            <p>
              <input name="service" value="<?php echo htmlentities($value1); ?>" type="checkbox" />
              <span>Here is the first selection</span>
            </p>
            <p>
              <input name="service" value="<?php echo htmlentities($value2); ?>" type="checkbox" />
              <span>Here is the second selection</span>
            </p>
            <p>
              <input name="service" value="<?php echo htmlentities($value3); ?>" type="checkbox" />
              <span>Here is the third selection</span>
            </p>
            <p>
              <input name="service" value="<?php echo htmlentities($value4); ?>" type="checkbox" />
              <span>Here is the fourth selection</span>
            </p>
          </div>
     
          <p><label>Message: <br />
          <textarea name="message" class="textarea" title="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
          </label><br /><span class="errors"><?php echo $messageErr ?></span></p>
     
          <p><input type="submit" name="submit" class="button" value="Submit" /><input type="reset" name="reset" class="button" value="Reset" /></p></form>
      </div>
    <!--content ends above here-->
    <?php include 'footer.php'; ?>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,495
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    There must be something named the same on both forms ...
    where the script can't figure out which one you're validating.

    I see you have different form id's ...
    id="contact_form"
    id="services_form"

    But these are the same:
    <div id="contact_form_wrap">

    And these are the same:
    name="formID"

    I suspect the "formID" will be the culprit.


    .

  • Users who have thanked mlseim for this post:

    chevy_ls_6 (04-12-2012)

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,324
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Well get rid of if($_POST['submit']) in both form processing blocks and see what happens. Check the details in my signature for reasons why.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #4
    Regular Coder
    Join Date
    Aug 2009
    Posts
    160
    Thanks
    42
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by tangoforce View Post
    Well get rid of if($_POST['submit']) in both form processing blocks and see what happens. Check the details in my signature for reasons why.
    Heck, I'm just trying to get it working in FireFox for now...I'll worry about IE later, lol!

    I ran across a couple different techniques on the web, but when I implement them it seems to break the validation...the way it is now, either submit button validates *both* forms. Uggh...

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    The way I would resolve this would be to put a hidden form field in each form with the same name ('formid' would do) but a different value.

    You then test for the existence of that field in order to determine that there is a form that has been submitted and needs to be validated and examine the value of the field in order to determine which form to validate.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    chevy_ls_6 (04-12-2012)

  • #6
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,324
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Right, debug time:

    At the top of the processing script:

    print_r($_POST);

    Report back with the results.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    chevy_ls_6 (04-12-2012)

  • #7
    Regular Coder
    Join Date
    Aug 2009
    Posts
    160
    Thanks
    42
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by tangoforce View Post
    Right, debug time:

    At the top of the processing script:

    print_r($_POST);

    Report back with the results.
    When I hit submit on top (contact) form:
    Array ( [formID] => contact [name] => [email] => [message] => [submit] => Submit )

    When I hit submit on bottom (services) form:
    Array ( [formID] => services [name] => [email] => [phone] => [location] => [message] => [submit] => Submit )

    Page url so y'all can mess with it: http://southlakeradiology.com/contact.php
    Last edited by chevy_ls_6; 04-12-2012 at 02:11 AM.

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,324
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Right I've got this nailed:

    PHP Code:
    include('validate.class.php');
    $v = new validate();

    //Get list of all errors I presume? - including missing fields..
    $errors $v->displayErrors(); 
    Then you have:
    PHP Code:
      <p class="contact"><span>Questions and/or Comments:</span>
    </p>

    <div id="contact_form_wrap">
        <span class="message"><?php echo $message_text?></span>
        <?php echo $errors?>
    and:
    PHP Code:
    <p class="contact"><span>Radiology Needs:</span>
    </p>
      <div id="contact_form_wrap">
        <span class="message"><?php echo $message_text?></span>
        <?php echo $errors?>
    You're generating error messages for one form that are then being used in one variable that is used in both forms to display error messages. That means you'll display the messages twice.

    This is proven by submitting the second form where I am then told the following - for the contact form:
    Name must be at least 3 characters long.
    Please enter an Email Address
    Phone must be at least 3 characters long.
    Location must be at least 3 characters long.
    Message must be at least 5 characters long.
    Instead of using '$errors' in both fields, try '$contactErrors' and '$serviceErrors'.

    Edit:
    Just to reaffirm, you are NOT seeing both procession blocks of code executing - you are simply duplicating the use of the error messages.
    Last edited by tangoforce; 04-12-2012 at 01:38 PM.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    chevy_ls_6 (04-12-2012)

  • #9
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,324
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Quote Originally Posted by felgall View Post
    The way I would resolve this would be to put a hidden form field in each form with the same name ('formid' would do) but a different value.

    You then test for the existence of that field in order to determine that there is a form that has been submitted and needs to be validated and examine the value of the field in order to determine which form to validate.
    Do you actually read opening posts before posting or do you just read the title? I only ask because if you'd read the post itself you'd have noticed that the op is already one step ahead of you.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #10
    Regular Coder
    Join Date
    Aug 2009
    Posts
    160
    Thanks
    42
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by tangoforce View Post
    Right I've got this nailed:
    Instead of using '$errors' in both fields, try '$contactErrors' and '$serviceErrors'.
    I'm tip-toeing into php here, but I assume I will then have to change the rest of the $errors in contact.php as well as the validating page (validate.class.php), basically 2 validating pages?

  • #11
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,324
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Quote Originally Posted by chevy_ls_6 View Post
    I'm tip-toeing into php here, but I assume I will then have to change the rest of the $errors in contact.php as well as the validating page (validate.class.php), basically 2 validating pages?
    In contact.php yes. In validate.class.php no.

    I've amended your php code below:

    Quote Originally Posted by chevy_ls_6 View Post
    PHP Code:
    <?php

    if ( $_POST['formID'] == 'contact') {

    define("EMAIL""contact@southlakeradiology.com");

    if(isset(
    $_POST['submit'])) {
     
      include(
    'validate.class.php');
     
      
    //assign post data to variables
      
    $name trim($_POST['name']);
        
    $email trim($_POST['email']);
        
    $message trim($_POST['message']);
        
     
      
    //start validating our form
      
    $v = new validate();
      
    $v->validateStr($name"name"375);
      
    $v->validateEmail($email"email");
      
    $v->validateStr($message"message"51000); 
     
      if(!
    $v->hasErrors()) {
            
    $header "From: $email\n" "Reply-To: $email\n";
            
    $subject "Form Submission";
            
    $email_to EMAIL;
     
            
    $emailMessage "Name: " $name "\n";
            
    $emailMessage .= "Email: " $email "\n";
            
    $emailMessage .= $message;
     
        
    //use php's mail function to send the email
            
    @mail($email_to$subject ,$emailMessage ,$header ); 
     
        
    //grab the current url, append ?sent=yes to it and then redirect to that url
            
    $url "http". ((!empty($_SERVER['HTTPS'])) ? "s" "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
            
    header('Location: '.$url."?sent=yes");
     
        } else {
        
    //set the number of errors message
        
    $message_text $v->errorNumMessage();      
     
        
    //store the errors list in a variable
       //*****************CHANGED THIS!!!**************
        
    $contactErrors $v->displayErrors();
     
        
    //get the individual error messages
        
    $nameErr $v->getError("name");
        
    $emailErr $v->getError("email");
        
    $messageErr $v->getError("message");
      }
    //end error check
    }// end isset
    }

    if ( 
    $_POST['formID'] == 'services') {
    define("EMAIL""contact@southlakeradiology.com");

    if(isset(
    $_POST['submit'])) {
     
      include(
    'validate.class.php');
     
      
    //assign post data to variables
      
    $name trim($_POST['name']);
        
    $email trim($_POST['email']);
        
    $phone trim($_POST['phone']);
        
    $location trim($_POST['location']);
        
    $value1 trim($_POST['value1']);
        
    $value2 trim($_POST['value2']);
        
    $value3 trim($_POST['value3']);
        
    $value4 trim($_POST['value4']);
        
    $message trim($_POST['message']);
        
     
      
    //start validating our form
      
    $v = new validate();
      
    $v->validateStr($name"name"375);
      
    $v->validateEmail($email"email");
      
    $v->validateStr($phone"phone"375);
      
    $v->validateStr($location"location"375);
      
    $v->validateStr($message"message"51000); 
     
      if(!
    $v->hasErrors()) {
            
    $header "From: $email\n" "Reply-To: $email\n";
            
    $subject "Form Submission";
            
    $email_to EMAIL;
     
            
    $emailMessage "Name: " $name "\n";
            
    $emailMessage .= "Email: " $email "\n";
            
    $emailMessage .= "Phone: " $phone "\n";
            
    $emailMessage .= "Location: " $location "\n";
            
    $emailMessage .= "Value1: " $email "\n";
            
    $emailMessage .= "Value2: " $email "\n";
            
    $emailMessage .= "Value3: " $email "\n";
            
    $emailMessage .= "Value4: " $email "\n";        
            
    $emailMessage .= $message;
     
        
    //use php's mail function to send the email
            
    @mail($email_to$subject ,$emailMessage ,$header ); 
     
        
    //grab the current url, append ?sent=yes to it and then redirect to that url
            
    $url "http". ((!empty($_SERVER['HTTPS'])) ? "s" "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
            
    header('Location: '.$url."?sent=yes");
     
        } else {
        
    //set the number of errors message
        
    $message_text $v->errorNumMessage();      
     
        
    //store the errors list in a variable
       //*****************CHANGED THIS!!!**************
        
    $serviceErrors $v->displayErrors();
     
        
    //get the individual error messages
        
    $nameErr $v->getError("name");
        
    $emailErr $v->getError("email");
        
    $phoneErr $v->getError("phone");
        
    $locationErr $v->getError("location");
        
    $messageErr $v->getError("message");
      }
    //end error check
    }// end isset
    }
    ?>

    <?php include 'header.php'?>
    <!--content starts below here-->
    ********UNDER CONSTRUCTION********
    <p class="contact"><span>Toll Free Numbers:</span>&nbsp;Office (866) 333-8443 or Fax (866) 316-0080
    </p>
      <p class="contact"><span>Questions and/or Comments:</span>
    </p>

    <div id="contact_form_wrap">
        <span class="message"><?php echo $message_text?></span>
        <?php echo $contactErrors?>
        <?php if(isset($_GET['sent'])): ?><span class="sent">Your message has been sent</span><?php endif; ?>
        <form id="contact_form" method="post" action="contact.php"><input type="hidden" name="formID"
    value="contact">
          <p><label>Name:<br />
          <input type="text" name="name" class="textfield" title="name" value="<?php echo htmlentities($name); ?>" />
          </label><br /><span class="errors"><?php echo $nameErr?></span></p>
     
          <p><label>Email: <br />
          <input type="text" name="email" class="textfield" title="email" value="<?php echo htmlentities($email); ?>" />
          </label><br /><span class="errors"><?php echo $emailErr ?></span></p>         
     
          <p><label>Message: <br />
          <textarea name="message" class="textarea" title="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
          </label><br /><span class="errors"><?php echo $messageErr ?></span></p>
     
          <p><input type="submit" name="submit" class="button" value="Submit" /><input type="reset" name="reset" class="button" value="Reset" /></p></form>
      </div>

    <p class="contact"><span>Radiology Needs:</span>
    </p>
      <div id="contact_form_wrap">
        <span class="message"><?php echo $message_text?></span>
        <?php echo $serviceErrors?>
        <?php if(isset($_GET['sent'])): ?><span class="sent">Your message has been sent</span><?php endif; ?>
        <form id="services_form" method="post" action="contact.php"><input type="hidden" name="formID"
    value="services">
          <p><label>Name:<br />
          <input type="text" name="name" class="textfield" title="name" value="<?php echo htmlentities($name); ?>" />
          </label><br /><span class="errors"><?php echo $nameErr?></span></p>
     
          <p><label>Email: <br />
          <input type="text" name="email" class="textfield" title="email" value="<?php echo htmlentities($email); ?>" />
          </label><br /><span class="errors"><?php echo $emailErr ?></span></p>        
          
          <p><label>Phone: <br />
          <input type="text" name="phone" class="textfield" title="phone" value="<?php echo htmlentities($phone); ?>" />
          </label><br /><span class="errors"><?php echo $phoneErr ?></span></p>  
     
           <p><label>Location For Requested Services: <br />
          <input type="text" name="location" class="textfield" title="location" value="<?php echo htmlentities($location); ?>" />
          </label><br /><span class="errors"><?php echo $locationErr ?></span></p>
     
           <div class="clearfix">
            <p>
              <input name="service" value="<?php echo htmlentities($value1); ?>" type="checkbox" />
              <span>Here is the first selection</span>
            </p>
            <p>
              <input name="service" value="<?php echo htmlentities($value2); ?>" type="checkbox" />
              <span>Here is the second selection</span>
            </p>
            <p>
              <input name="service" value="<?php echo htmlentities($value3); ?>" type="checkbox" />
              <span>Here is the third selection</span>
            </p>
            <p>
              <input name="service" value="<?php echo htmlentities($value4); ?>" type="checkbox" />
              <span>Here is the fourth selection</span>
            </p>
          </div>
     
          <p><label>Message: <br />
          <textarea name="message" class="textarea" title="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
          </label><br /><span class="errors"><?php echo $messageErr ?></span></p>
     
          <p><input type="submit" name="submit" class="button" value="Submit" /><input type="reset" name="reset" class="button" value="Reset" /></p></form>
      </div>
    <!--content ends above here-->
    <?php include 'footer.php'?>
    That *SHOULD* fix it but if not please let us know.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    chevy_ls_6 (04-12-2012)

  • #12
    Regular Coder
    Join Date
    Aug 2009
    Posts
    160
    Thanks
    42
    Thanked 2 Times in 2 Posts
    tango: I had tried simply changing those 2 variables already (contactError and servicesError), and it still acts the same...your block of code is currently running on that page.

    What's gonna be a p!sser is when the owner changes his mind and decides he wants the forms split across 2 pages, lol...
    Last edited by chevy_ls_6; 04-12-2012 at 06:52 PM.

  • #13
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,324
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Quote Originally Posted by chevy_ls_6 View Post
    tango: ... it still acts the same...
    No it doesn't. In fact it's made a very big difference only you're not sharp eyed enough to have noticed it.

    Look at the form again and click submit for each one. Notice how now you only get error messages above the Name box for the correct form? - Previously you had them above both Name boxes. This means my changes have worked but I hadn't realised you were also outputting errors under each box. Again thats the same cause - using the same variable names.

    Revised code:
    PHP Code:
    <?php

    if ( $_POST['formID'] == 'contact') {

    define("EMAIL""contact@southlakeradiology.com");

    if(isset(
    $_POST['submit'])) {
     
      include(
    'validate.class.php');
     
      
    //assign post data to variables
      
    $name trim($_POST['name']);
        
    $email trim($_POST['email']);
        
    $message trim($_POST['message']);
        
     
      
    //start validating our form
      
    $v = new validate();
      
    $v->validateStr($name"name"375);
      
    $v->validateEmail($email"email");
      
    $v->validateStr($message"message"51000); 
     
      if(!
    $v->hasErrors()) {
            
    $header "From: $email\n" "Reply-To: $email\n";
            
    $subject "Form Submission";
            
    $email_to EMAIL;
     
            
    $emailMessage "Name: " $name "\n";
            
    $emailMessage .= "Email: " $email "\n";
            
    $emailMessage .= $message;
     
        
    //use php's mail function to send the email
            
    @mail($email_to$subject ,$emailMessage ,$header ); 
     
        
    //grab the current url, append ?sent=yes to it and then redirect to that url
            
    $url "http". ((!empty($_SERVER['HTTPS'])) ? "s" "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
            
    header('Location: '.$url."?sent=yes");
     
        } else {
        
    //set the number of errors message
        
    $contact_message_text $v->errorNumMessage();      
     
        
    //store the errors list in a variable
       //*****************CHANGED THIS!!!**************
        
    $contactErrors $v->displayErrors();
     
        
    //get the individual error messages
        
    $contact_nameErr $v->getError("name");
        
    $contact_emailErr $v->getError("email");
        
    $contact_messageErr $v->getError("message");
      }
    //end error check
    }// end isset
    }

    if ( 
    $_POST['formID'] == 'services') {
    define("EMAIL""contact@southlakeradiology.com");

    if(isset(
    $_POST['submit'])) {
     
      include(
    'validate.class.php');
     
      
    //assign post data to variables
      
    $name trim($_POST['name']);
        
    $email trim($_POST['email']);
        
    $phone trim($_POST['phone']);
        
    $location trim($_POST['location']);
        
    $value1 trim($_POST['value1']);
        
    $value2 trim($_POST['value2']);
        
    $value3 trim($_POST['value3']);
        
    $value4 trim($_POST['value4']);
        
    $message trim($_POST['message']);
        
     
      
    //start validating our form
      
    $v = new validate();
      
    $v->validateStr($name"name"375);
      
    $v->validateEmail($email"email");
      
    $v->validateStr($phone"phone"375);
      
    $v->validateStr($location"location"375);
      
    $v->validateStr($message"message"51000); 
     
      if(!
    $v->hasErrors()) {
            
    $header "From: $email\n" "Reply-To: $email\n";
            
    $subject "Form Submission";
            
    $email_to EMAIL;
     
            
    $emailMessage "Name: " $name "\n";
            
    $emailMessage .= "Email: " $email "\n";
            
    $emailMessage .= "Phone: " $phone "\n";
            
    $emailMessage .= "Location: " $location "\n";
            
    $emailMessage .= "Value1: " $email "\n";
            
    $emailMessage .= "Value2: " $email "\n";
            
    $emailMessage .= "Value3: " $email "\n";
            
    $emailMessage .= "Value4: " $email "\n";        
            
    $emailMessage .= $message;
     
        
    //use php's mail function to send the email
            
    @mail($email_to$subject ,$emailMessage ,$header ); 
     
        
    //grab the current url, append ?sent=yes to it and then redirect to that url
            
    $url "http". ((!empty($_SERVER['HTTPS'])) ? "s" "") . "://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
            
    header('Location: '.$url."?sent=yes");
     
        } else {
        
    //set the number of errors message
        
    $service_message_text $v->errorNumMessage();      
     
        
    //store the errors list in a variable
       //*****************CHANGED THIS!!!**************
        
    $serviceErrors $v->displayErrors();
     
        
    //get the individual error messages
        
    $service_nameErr $v->getError("name");
        
    $service_emailErr $v->getError("email");
        
    $service_phoneErr $v->getError("phone");
        
    $service_locationErr $v->getError("location");
        
    $service_messageErr $v->getError("message");
      }
    //end error check
    }// end isset
    }
    ?>

    <?php include 'header.php'?>
    <!--content starts below here-->
    ********UNDER CONSTRUCTION********
    <p class="contact"><span>Toll Free Numbers:</span>&nbsp;Office (866) 333-8443 or Fax (866) 316-0080
    </p>
      <p class="contact"><span>Questions and/or Comments:</span>
    </p>

    <div id="contact_form_wrap">
        <span class="message"><?php echo $contact_message_text?></span>
        <?php echo $contactErrors?>
        <?php if(isset($_GET['sent'])): ?><span class="sent">Your message has been sent</span><?php endif; ?>
        <form id="contact_form" method="post" action="contact.php"><input type="hidden" name="formID"
    value="contact">
          <p><label>Name:<br />
          <input type="text" name="name" class="textfield" title="name" value="<?php echo htmlentities($name); ?>" />
          </label><br /><span class="errors"><?php echo $contact_nameErr?></span></p>
     
          <p><label>Email: <br />
          <input type="text" name="email" class="textfield" title="email" value="<?php echo htmlentities($email); ?>" />
          </label><br /><span class="errors"><?php echo $contact_emailErr ?></span></p>         
     
          <p><label>Message: <br />
          <textarea name="message" class="textarea" title="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
          </label><br /><span class="errors"><?php echo $contact_messageErr ?></span></p>
     
          <p><input type="submit" name="submit" class="button" value="Submit" /><input type="reset" name="reset" class="button" value="Reset" /></p></form>
      </div>

    <p class="contact"><span>Radiology Needs:</span>
    </p>
      <div id="contact_form_wrap">
        <span class="message"><?php echo $service_message_text?></span>
        <?php echo $serviceErrors?>
        <?php if(isset($_GET['sent'])): ?><span class="sent">Your message has been sent</span><?php endif; ?>
        <form id="services_form" method="post" action="contact.php"><input type="hidden" name="formID"
    value="services">
          <p><label>Name:<br />
          <input type="text" name="name" class="textfield" title="name" value="<?php echo htmlentities($name); ?>" />
          </label><br /><span class="errors"><?php echo $service_nameErr?></span></p>
     
          <p><label>Email: <br />
          <input type="text" name="email" class="textfield" title="email" value="<?php echo htmlentities($email); ?>" />
          </label><br /><span class="errors"><?php echo $service_emailErr ?></span></p>        
          
          <p><label>Phone: <br />
          <input type="text" name="phone" class="textfield" title="phone" value="<?php echo htmlentities($phone); ?>" />
          </label><br /><span class="errors"><?php echo $service_phoneErr ?></span></p>  
     
           <p><label>Location For Requested Services: <br />
          <input type="text" name="location" class="textfield" title="location" value="<?php echo htmlentities($location); ?>" />
          </label><br /><span class="errors"><?php echo $service_locationErr ?></span></p>
     
           <div class="clearfix">
            <p>
              <input name="service" value="<?php echo htmlentities($value1); ?>" type="checkbox" />
              <span>Here is the first selection</span>
            </p>
            <p>
              <input name="service" value="<?php echo htmlentities($value2); ?>" type="checkbox" />
              <span>Here is the second selection</span>
            </p>
            <p>
              <input name="service" value="<?php echo htmlentities($value3); ?>" type="checkbox" />
              <span>Here is the third selection</span>
            </p>
            <p>
              <input name="service" value="<?php echo htmlentities($value4); ?>" type="checkbox" />
              <span>Here is the fourth selection</span>
            </p>
          </div>
     
          <p><label>Message: <br />
          <textarea name="message" class="textarea" title="textarea" cols="45" rows="5"><?php echo htmlentities($message); ?></textarea>
          </label><br /><span class="errors"><?php echo $service_messageErr ?></span></p>
     
          <p><input type="submit" name="submit" class="button" value="Submit" /><input type="reset" name="reset" class="button" value="Reset" /></p></form>
      </div>
    <!--content ends above here-->
    <?php include 'footer.php'?>
    You should start to notice some differences now.

    Quote Originally Posted by chevy_ls_6 View Post

    What's gonna be a p!sser is when the owner changes his mind and decides he wants the forms split across 2 pages, lol...
    Not really, tell him to hire me as part of the gang
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    chevy_ls_6 (04-12-2012)

  • #14
    Regular Coder
    Join Date
    Aug 2009
    Posts
    160
    Thanks
    42
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by tangoforce View Post
    No it doesn't. In fact it's made a very big difference only you're not sharp eyed enough to have noticed it.
    Ha! I'd agree with that!


    Quote Originally Posted by tangoforce View Post
    You should start to notice some differences now.

    Not really, tell him to hire me as part of the gang
    Yep, that did the trick...and he'd be money/time ahead if he did hire you, lol!

    BTW: I think I caught a mistake I had made in the original "services" code that has gotten repeated:

    It was...
    PHP Code:
            $emailMessage "Name: " $name "\n";
            
    $emailMessage .= "Email: " $email "\n";
            
    $emailMessage .= "Phone: " $phone "\n";
            
    $emailMessage .= "Location: " $location "\n";
            
    $emailMessage .= "Value1: " $email "\n";
            
    $emailMessage .= "Value2: " $email "\n";
            
    $emailMessage .= "Value3: " $email "\n";
            
    $emailMessage .= "Value4: " $email "\n";        
            
    $emailMessage .= $message
    But should be...(if I'm not mistaken)
    PHP Code:
            $emailMessage "Name: " $name "\n";
            
    $emailMessage .= "Email: " $email "\n";
            
    $emailMessage .= "Phone: " $phone "\n";
            
    $emailMessage .= "Location: " $location "\n";
            
    $emailMessage .= "Value1: " $value1 "\n";
            
    $emailMessage .= "Value2: " $value2 "\n";
            
    $emailMessage .= "Value3: " $value3 "\n";
            
    $emailMessage .= "Value4: " $value4 "\n";        
            
    $emailMessage .= $message
    And again, MANY THANKS to all those who helped me with this, especially you, tango!

    Now, I guess I need to work on that whole IE _post isset issue...!

  • #15
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,324
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    You can remove the isset($_POST) part from both clauses (along with the matching { and }). It's just not needed - you're already looking for your hidden fields.

    No comment on the other thing regarding the code you've posted, I never looked at it as it wasn't part of the problem I was dealing with.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    chevy_ls_6 (04-12-2012)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •