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 6 of 6
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    19
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Unhappy PHP Form (display submitted data)

    Hi

    I have created a form with a php mail function. Once the submit button is pressed, the mail successfully sends to the specified email address, and then the process page is displayed. I am trying to get all the submitted field contents to display on the process form once the form is submitted so that I can provide "print" and "save" buttons, but my code is not working. any advice would be greatly appreciated. Thank you

    Now, once the form is submitted - it displays the page 'processed' (this processed page is named:?page_id=2601.php) - but there is no data displaying on the page?

    Code:
    <?php
    if(isset($_POST['submit'])) {
    $to = 'myemail@yahoo.com' ; //put your email address on which you want to receive the information
    $subject = 'Conference Quote Request'; //set the subject of email.
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $message = "<table><tr><td>Enquiry Date</td><td>".$_POST['dateToday']."</td></tr>
    <tr><td>Conference Name</td><td>".$_POST['conferenceName']."</td></tr>
    <tr><td>Company Name</td><td>".$_POST['companyName']."</td></tr>
    <tr><td>First Name</td><td>".$_POST['firstName']."</td></tr>
    <tr><td>Last Name</td><td>".$_POST['lastName']."</td></tr>
    <tr><td>Tel No</td><td>".$_POST['telNo']."</td></tr>
    <tr><td>E-Mail</td><td>".$_POST['cellNo']."</td></tr>
    <tr><td>E-Mail</td><td>".$_POST['email']."</td></tr>
    <tr><td>Special Requests</td><td>".$_POST['comment']."</td></tr>
    </tr></table>" ;
    echo "Message sent successfully...";
    mail($to, $subject, $message, $headers);
    header('Location: ?page_id=2601.php');
    var_dump($_POST);
    }
    ?>

  • #2
    Regular Coder
    Join Date
    Jun 2009
    Posts
    146
    Thanks
    3
    Thanked 21 Times in 21 Posts
    I suspect on the next page you are trying to view post variables, however because you used a header redirect

    PHP Code:
    header('Location: ?page_id=2601.php'); 
    They do not exist, you can either

    A) Put your success message below the email sent and then exit(), so that you do not need to be redirected

    or

    B) You have to pass the variables through your header redirection through to the new page, which means echoing them into the URL and accessing them via the GET method

  • Users who have thanked itxtme for this post:

    Melissafleet (04-29-2013)

  • #3
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    in this script header() does exactly nothing. you can't set headers after outputing any text to client. headers are sent in the begining of output or not at all.

    as for your script, try this:
    PHP Code:
    <?php
    if(isset($_POST['submit'])) {
    $to 'myemail@yahoo.com' //put your email address on which you want to receive the information
    $subject 'Conference Quote Request'//set the subject of email.
    $headers 'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
    $message "<table><tr><td>Enquiry Date</td><td>".$_POST['dateToday']."</td></tr>
    <tr><td>Conference Name</td><td>"
    .$_POST['conferenceName']."</td></tr>
    <tr><td>Company Name</td><td>"
    .$_POST['companyName']."</td></tr>
    <tr><td>First Name</td><td>"
    .$_POST['firstName']."</td></tr>
    <tr><td>Last Name</td><td>"
    .$_POST['lastName']."</td></tr>
    <tr><td>Tel No</td><td>"
    .$_POST['telNo']."</td></tr>
    <tr><td>E-Mail</td><td>"
    .$_POST['cellNo']."</td></tr>
    <tr><td>E-Mail</td><td>"
    .$_POST['email']."</td></tr>
    <tr><td>Special Requests</td><td>"
    .$_POST['comment']."</td></tr>
    </tr></table>" 
    ;

        if(
    mail($to$subject$message$headers)){
           echo 
    "Message sent successfully...<br />";
           echo 
    $message;
        }else{
           echo 
    'Error! try again';
        }
    }
    ?>
    Last edited by patryk; 04-29-2013 at 11:17 PM.

    -------------------------------------------------------------------------------
    "Real Programmers can write assembly code in any language" - Larry Wall

  • Users who have thanked patryk for this post:

    Melissafleet (04-29-2013)

  • #4
    New Coder
    Join Date
    Oct 2011
    Posts
    19
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Thank you very much.
    It is working perfectly

    Would I use .Php to create a print to PDF button for the submitted results?

  • #5
    Regular Coder patryk's Avatar
    Join Date
    Oct 2012
    Location
    /dev/couch
    Posts
    398
    Thanks
    2
    Thanked 64 Times in 64 Posts
    yes you can use php to create pdf file (not a button per se though).
    you could use built in pdf functions: http://php.net/manual/en/book.pdf.php
    or some class like that for example http://www.fpdf.org/
    you'll find planty of tutorials how to do it

    -------------------------------------------------------------------------------
    "Real Programmers can write assembly code in any language" - Larry Wall

  • Users who have thanked patryk for this post:

    Melissafleet (04-30-2013)

  • #6
    New Coder
    Join Date
    Oct 2011
    Posts
    19
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Thank you for your help.

    I am now encountering another issue with this, sometimes when I submit my form data, I receive this error:

    Code:
    Forbidden
    
    You don't have permission to access / on this server.
    
    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
    I have tried changing my .htaccess file to this, but it still bring up the error?

    Code:
    Options +FollowSymLinks
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    
    # END WordPress


  •  

    Tags for this Thread

    Posting Permissions

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