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.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Feedback Form Issue.

    Now I got the feedback form to work, and it gives me a confirmation page. What I really want is after the user hits the "submit" button, I want the message to be sent. And not get the confirmation page, but instead just reload or reset back to its original contact form page.

    Current Code [ HTML ]

    Code:
    <form method="post" action="contact_a.php">
    	  		
    
    <label for="fullname">Full Name</label> <input type="text" name="fullname" id="fullname" /><br /> <label for="email">Email</label> <input type="text" name="email" id="email" /><br /> <label for="topic">Subject</label> <input type="text" name="topic" id="topic" /><br /> <label for="info">Message</label> <textarea name="info" rows="10" wrap="virtual" id="info"></textarea> <input type="submit" value="Submit" name="submit" />
    </form>
    Current Code [ PHP ]

    Code:
    <?php
      $name = $_POST['fullname'];
      $email = $_POST['email'];
      $title = $_POST['topic'];
      $body = $_POST['info'];
      
      $to = 'demo@email.com';
      $subject = "$title";
      $msg = "$body";
      mail($to, $subject, $msg, 'From:' . $email);
    ?>
    Side Note: Before you say anything about the confirmation page / PHP code, there is actually a Thank You Note in HTML form.


    I'd appreciate any help. Thank You.

  • #2
    Regular Coder
    Join Date
    May 2009
    Location
    Moore, OK
    Posts
    282
    Thanks
    11
    Thanked 41 Times in 41 Posts
    I think this is what you want. You should validate all you data before sending the email. Just FYI. Not exactly a secure form but a simple one.
    PHP Code:
    <?php
    $name 
    '';
    $email '';
    $title '';
    $body '';
    $message 'Please fill out this form to send me an email.';

    // Check if form is submitted.
    if (isset ($_POST['submit'])) {
      
    $name $_POST['fullname'];
      
    $email $_POST['email'];
      
    $title $_POST['topic'];
      
    $body $_POST['info'];
      
      
    $to 'demo@email.com';
      
    $subject "$title";
      
    $msg "$body";

      
    // If the email sends give the user a success message.
      
    if (mail($to$subject$msg'From:' $email)) {
        
    $message 'Thank you for your response.  I will get back to you as soon as possible.';
      }
      else {
        
    $message 'Sorry there was an error sending you email.';
      }
    }
    ?>
    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <?php
      
    if ((isset ($message)) && ($message != '')) {
        echo 
    "<p>$message</p>";
      }
    ?>
    <label for="fullname">Full Name</label>
    <input type="text" name="fullname" id="fullname" value="<?php echo $name?>" /><br />
                  
    <label for="email">Email</label>
    <input type="text" name="email" id="email" value="<?php echo $email?>" /><br />
                  
    <label for="topic">Subject</label>
    <input type="text" name="topic" id="topic"  value="<?php echo $title?>"/><br />
                                
    <label for="info">Message</label>
    <textarea name="info" rows="10" wrap="virtual" id="info"><?php echo $body?>"</textarea>
                  
    <input type="submit" value="Submit" name="submit" />
    </form>

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I appreciate the reply. But there was one thing I forgot to mention is that.......

    The form is on contact.html while the php is on its own file contact_a.php

  • #4
    Regular Coder
    Join Date
    May 2009
    Location
    Moore, OK
    Posts
    282
    Thanks
    11
    Thanked 41 Times in 41 Posts
    If you want them to be able to see the form they need to be on the same script... also change the contact.html to contact.php because html files can be downloaded and php cannot. Basically I already accounted for that with the action going to $_SERVER['PHP_SELF']; So just change the form name as I mentioned and you should be good to go.

  • #5
    Regular Coder
    Join Date
    May 2009
    Location
    Moore, OK
    Posts
    282
    Thanks
    11
    Thanked 41 Times in 41 Posts
    Or if you don't want them to get the variables back or a message just add this to the bottom of your contact_a.php page.

    PHP Code:
    header ('Location: http://www.example.com/contact.html');
    exit(); 

  • #6
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Quote Originally Posted by pminister View Post
    I appreciate the reply. But there was one thing I forgot to mention is that.......

    The form is on contact.html while the php is on its own file contact_a.php
    That shows clearly in your original post. But in my opinion it's better to use one file as in Coyote6 example on post #2. It makes updating - and debugging - a lot easier with fewer files.


    ------------------------------
    Leonard Whistler

  • #7
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well i tried the one page method as suggested. Now when i first go to the php page, and if i dont enter any info and still hit the submit button. It will give me the thank you message anyway, but won't send me an email.

    2nd thing is... Say after entering the info, then hit submit. Well it sends the email, but the info i entered stays.

    Thanks again.

  • #8
    Regular Coder
    Join Date
    Jul 2003
    Posts
    117
    Thanks
    0
    Thanked 17 Times in 17 Posts
    You have to validate the form input See the pages below for an example:
    PHP based email contact form

    PHP form tutorial


  •  

    Posting Permissions

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