www.webdeveloper.com
Results 1 to 7 of 7

Thread: I am looking for PHP contact form for this template

  1. #1
    Join Date
    Jun 2003
    Posts
    445

    I am looking for PHP contact form for this template

    I am looking for PHP contact form for this template. It will also include code for a redirect link to a Thank you page. The redirecting code I have is from an older mailing form, but the mailing form doesn't work for the new template.

    PHP Code:
    timeOut "0001"

    newSite "thank_you.html";

    function 
    timer() { self.setTimeout("self.location.href = newSite;",timeOut); } 

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    727
    "For this template."

    ???
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL | E_NOTICE);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

  3. #3
    Join Date
    Jun 2003
    Posts
    445
    ginerjm, if you scroll down on the link I provided it shows a google map, then beneath that are fields for Name, Email, Subject, and Message. I assume I would use PHP code for the action: action="contact.php", and that's what I'm looking for.

  4. #4
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    727
    This forum is for people to show code for which they have a problem. Not to take us to who knows where for spam, viruses or whatever harm idle minds have in store for us. That said, I didn't see a link in your message until you just now told me to look for one.

    A little more explanation about what problem you are having would be in order. Unless you are asking us to write your code for you, which we won't do.

    PS - Why not just write your own contact form? A pretty basic thing to do, whether you're new to php or not.
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL | E_NOTICE);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

  5. #5
    Join Date
    Oct 2013
    Posts
    486
    See next. Gaaack.
    Last edited by Kevin2; 08-12-2014 at 04:09 PM.

  6. #6
    Join Date
    Oct 2013
    Posts
    486
    In defense of ginerjm: I didn't see the link either, but after knowing one was there I clicked on it, come what may . See below.

    In defense of OP: It is very difficult to tell the difference between 'standard text' and text that is a link. The font-weight, color, etc. in this forum's CSS make it almost impossible to differentiate between them. Unfortunately, one must hang around here a few months to know that when you need to post a link it's better to just paste the URL rather than highlight/[click link button]/paste URL.

    Anyway, to the OP: start here:
    http://validator.w3.org/check?uri=ht...Inline&group=0

  7. #7
    Join Date
    Jun 2003
    Posts
    445
    ginerjm, I'm actually not a developer, so this stuff isn't easy for me. I can edit the code little bit here and there, but I mostly copy and paste. Kevin2, the validator is looking at the HTML of the page, and the PHP is my concern.

    This is the HTML action calling for the PHP:

    PHP Code:
    <form method="post" action="contact.php">
    <
    div class="contact-to">
    <
    input type="text" class="text" value="Name..." onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Name...';}">
    <
    input type="text" class="text" value="Email..." onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Email...';}" style="margin-left: 10px">
    <
    input type="text" class="text" value="Subject..." onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Subject...';}" style="margin-left: 10px">
    </
    div>
    <
    div class="text2">
    <
    textarea value="Message:" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Message';}">Message..</textarea>
    </
    div>
    <
    div>
    <
    a href="thank_you.html" class="submit">Submit</a>
    </
    div>
    </
    form
    And this is the PHP that I have:

    PHP Code:


    <?php
     
    if(isset($_POST['email'])) {
     
         
     
        
    // EDIT THE 2 LINES BELOW AS REQUIRED
     
        
    $email_to "email address here";
     
        
    $email_subject "Your email subject line";
     
         
     
         
     
        function 
    died($error) {
     
            
    // your error code can go here
     
            
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
     
            echo 
    "These errors appear below.<br /><br />";
     
            echo 
    $error."<br /><br />";
     
            echo 
    "Please go back and fix these errors.<br /><br />";
     
            die();
     
        }
     
         
     
        
    // validation expected data exists
     
        
    if(!isset($_POST['Name...']) ||
     
            !isset(
    $_POST['Email...']) ||
     
            !isset(
    $_POST['Subject...']) ||
     
            !isset(
    $_POST['Message:']) ||
            
            <!-- 
     
            !isset(
    $_POST['Message:'])) { -->
     
            
    died('We are sorry, but there appears to be a problem with the form you submitted.');       
     
        }
     
         
     
        
    $first_name $_POST['Name...']; // required
     
        
    $last_name $_POST['Email...']; // required
     
        
    $email_from $_POST['Subject...']; // required
     
        
    $comments $_POST['Message:']; // required
     
         
     
        
    $error_message "";
     
        
    $email_exp '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
     
      if(!
    preg_match($email_exp,$email_from)) {
     
        
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
     
      }
     
        
    $string_exp "/^[A-Za-z .'-]+$/";
     
      if(!
    preg_match($string_exp,$first_name)) {
     
        
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
     
      }
     
      if(!
    preg_match($string_exp,$last_name)) {
     
        
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
     
      }
     
      if(
    strlen($comments) < 2) {
     
        
    $error_message .= 'The Comments you entered do not appear to be valid.<br />';
     
      }
     
      if(
    strlen($error_message) > 0) {
     
        
    died($error_message);
     
      }
     
        
    $email_message "Form details below.\n\n";
     
         
     
        function 
    clean_string($string) {
     
          
    $bad = array("content-type","bcc:","to:","cc:","href");
     
          return 
    str_replace($bad,"",$string);
     
        }
     
         
     
        
    $email_message .= "Name: ".clean_string($Name...)."\n";
     
        
    $email_message .= "Email: ".clean_string($Email...)."\n";
     
        
    $email_message .= "Subject: ".clean_string($Subject...)."\n";
     
        
    $email_message .= "Message: ".clean_string($Message:)."\n";
     
         
     
         
     
    // create email headers
     
    $headers 'From: '.$email_from."\r\n".
     
    'Reply-To: '.$email_from."\r\n" .
     
    'X-Mailer: PHP/' phpversion();
     
    @
    mail($email_to$email_subject$email_message$headers);  
     
    ?>
     
     
     
    <!-- include your own success html here -->
     
     
     
    Thank you for contacting us. We will be in touch with you very soon.
     
     
     
    <?php
     
    }
     
    ?>
    I also see that the HTML is calling for a Thank You page, but the PHP code toward the end has its own Thank you message that probably should appear without launching the Thank you HTML page? So, at this point I probably shouldn't even have a Thank You HTML page if the PHP is going to show this message... and where does it show it?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles