Thread: PHP Form POST

Page 1 of 3 123 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    27
    Rep Power
    0

    PHP Form POST


    hi there

    I am posting my form table values to another page by using 'submit. Is it possible to use the ".$_POST" function to send the entire table to the next page, instead of doing it one field at a time?

    This is the code for the table I am trying to submit:

    Code:
    <table id="tablex" border="1" cellspacing="3" cellpadding="3">
    <tbody>
    <tr>
    <th scope="col" width="30">
    <div align="center">Date</div></th>
    <th scope="col" width="128">
    <div align="center">Amount of Delegates  Day Conference @ R 240 pp</div></th>
    <th width="112">
    <div align="center">Amount of Delegates Full Day Conference @ R 260 pp</div></th>
    <th width="112">
    <div align="center">Menu No</div></th>
    <th width="112">
    <div align="center">Price pp for Menu (1-7: R70, 8-10 R85, 11: R105, 12: R85)</div></th>
    <th width="112">
    <div align="center">Total Persons for meals</div></th>
    <th width="112">
    <div align="center">Amount of Single Rooms @ R 480 pp</div></th>
    <th width="112">
    <div align="center">Amount of Double Rooms @ R 720 pp</div></th>
    <th width="134">
    <div align="center">Total for the day</div></th>
    </tr>
    <tr>
    <td>
    <div align="center"><input type="text" name="date1" size="10" /></div></td>
    <td>
    <div align="center"><input type="text" name="halfday1" size="5" maxlength="10" /></div></td>
    <td>
    <div align="center"><input type="text" name="fullday1" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MenuNo1" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MenuPrice1" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MealPersons1" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="SingleRooms1" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="DoubleRooms1" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="total1" size="5" /></div></td>
    </tr>
    <tr>
    <td>
    <div align="center"><input type="text" name="date2" size="10" /></div></td>
    <td>
    <div align="center"><input type="text" name="halfday2" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="fullday2" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MenuNo2" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MenuPrice2" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MealPersons2" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="SingleRooms2" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="DoubleRooms2" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="total2" size="5" /></div></td>
    </tr>
    <tr>
    <td>
    <div align="center"><input type="text" name="date3" size="10" /></div></td>
    <td>
    <div align="center"><input type="text" name="halfday3" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="fullday3" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MenuNo3" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MenuPrice3" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MealPersons3" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="SingleRooms3" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="DoubleRooms3" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="total3" size="5" /></div></td>
    <td></td>
    </tr>
    <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    </tr>
    </tbody>
    </table>
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    Every field in a form will be in the $_POST array, yes.

    What is your actual question?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    27
    Rep Power
    0
    Originally Posted by ManiacDan
    Every field in a form will be in the $_POST array, yes.

    What is your actual question?
    I'm sorry for not being clear.

    My question is:

    Is there a way to POST the entire table to the next page in one line, instead of posting each individual field?

    Perhaps something like this:

    ".$_POST['tablex']." ?

    instead of doing it one by one:

    ".$_POST['date1']."
    ".$_POST['halfday1']."
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Location
    Burb of Detroit, Michigan
    Posts
    82
    Rep Power
    76
    First of all you have no
    Code:
    <form action="" method="post"> 
     
    <input id="submitButton" type="submit" name="data" value="Submit" />
    </form>
    so you code is going no where and I'm sure by looking at what you have you could consolidate you code where you wouldn't have to many $_POST variables. I don't know what you're doing, but that is what it looks like to me by looking at you table output. It also looks like it's screaming for some kind of database.
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    A blank form action posts back to the page that you're already on, this code is valid and will work.

    OP, if you want your entire POST array in a single string, just:
    PHP Code:
    $theString implode(';'$_POST); 
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    27
    Rep Power
    0

    Wink


    hi there.
    Thank you so much for all the replies.

    I left parts of my code out as it is very long. But I see now that it may be necessary to post all of it.

    This is the page that has the HTML form:

    Code:
    <form method="POST" id="quote" action="?page_id=2601.php">
    <script type="text/javascript">// <![CDATA[
    jQuery('#quote').keyup(function (){   doTotal(this);   calcMenu(this); });
    // ]]></script>
    <table id="table1" border="0" cellspacing="3" cellpadding="3">
    <tbody>
    <tr>
    <td>Enquiry Date</td>
    <td>
    <div align="center"><input type="text" name="dateToday" size="25" /></div></td>
    </tr>
    <tr>
    <td>Conference Name</td>
    <td>
    <div align="center"><input type="text" name="conferenceName" size="25" /></div></td>
    </tr>
    <tr>
    <td>Company Name</td>
    <td>
    <div align="center"><input type="text" name="companyName" size="25" /></div></td>
    </tr>
    <tr>
    <td>Special Requests</td>
    <td><textarea name="comment" rows="5" cols="26"></textarea></td>
    </tr>
    </tbody>
    </table>
    <table id="table2" border="0" cellspacing="3" cellpadding="3">
    <tbody>
    <tr>
    <td>First Name</td>
    <td>
    <div align="center"><input type="text" name="firstName" size="25" /></div></td>
    </tr>
    <tr>
    <td>Last Name</td>
    <td>
    <div align="center"><input type="text" name="lastName" size="25" /></div></td>
    </tr>
    <tr>
    <td>Tel No</td>
    <td>
    <div align="center"><input type="text" name="telNo" size="25" /></div></td>
    </tr>
    <tr>
    <td>Cell</td>
    <td>
    <div align="center"><input type="text" name="cellNo" size="25" /></div></td>
    </tr>
    <tr>
    <td>Email</td>
    <td>
    <div align="center"><input type="text" name="email" size="25" /></div></td>
    </tr>
    <tr>
    <td><input onclick="formReset()" type="button" value="Reset form" /></td>
    </tr>
    <tr>
    <td><input type="submit" value="Submit" name="submit"></td>
    </tr>
    </tbody>
    </table>
    <table id="tablex" border="1" cellspacing="3" cellpadding="3">
    <tbody>
    <tr>
    <th scope="col" width="30">
    <div align="center">Date</div></th>
    <th scope="col" width="128">
    <div align="center">Amount of Delegates  Day Conference @ R 240 pp</div></th>
    <th width="112">
    <div align="center">Amount of Delegates Full Day Conference @ R 260 pp</div></th>
    <th width="112">
    <div align="center">Menu No</div></th>
    <th width="112">
    <div align="center">Price pp for Menu (1-7: R70, 8-10 R85, 11: R105, 12: R85)</div></th>
    <th width="112">
    <div align="center">Total Persons for meals</div></th>
    <th width="112">
    <div align="center">Amount of Single Rooms @ R 480 pp</div></th>
    <th width="112">
    <div align="center">Amount of Double Rooms @ R 720 pp</div></th>
    <th width="134">
    <div align="center">Total for the day</div></th>
    </tr>
    <tr>
    <td>
    <div align="center"><input type="text" name="date1" size="10" /></div></td>
    <td>
    <div align="center"><input type="text" name="halfday1" size="5" maxlength="10" /></div></td>
    <td>
    <div align="center"><input type="text" name="fullday1" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MenuNo1" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MenuPrice1" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MealPersons1" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="SingleRooms1" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="DoubleRooms1" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="total1" size="5" /></div></td>
    </tr>
    <tr>
    <td>
    <div align="center"><input type="text" name="date2" size="10" /></div></td>
    <td>
    <div align="center"><input type="text" name="halfday2" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="fullday2" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MenuNo2" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MenuPrice2" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MealPersons2" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="SingleRooms2" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="DoubleRooms2" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="total2" size="5" /></div></td>
    </tr>
    <tr>
    <td>
    <div align="center"><input type="text" name="date3" size="10" /></div></td>
    <td>
    <div align="center"><input type="text" name="halfday3" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="fullday3" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MenuNo3" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MenuPrice3" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="MealPersons3" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="SingleRooms3" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="DoubleRooms3" size="5" /></div></td>
    <td>
    <div align="center"><input type="text" name="total3" size="5" /></div></td>
    <td></td>
    </tr>
    <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    </tr>
    </tbody>
    </table>
    </form>

    This is the page that my form data is posted to on "submit" :

    Code:
    <style>
    @media print { 
       .dontprint {
       display:none;
    } 
    }
    </style>
    <link href="process.css" rel="stylesheet" type="text/css" />
    <h1>Conference Quotation Estimate</h1>
    <?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>Cell No</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';
        }
    }
    ?>
    <script>
    function printpage()
    {
    window.print();
    }
    </script>
    
    <input type="button" value="Print this page" onclick="printpage()" class="dontprint" />
    
    <script>var pfHeaderImgUrl = '';var pfHeaderTagline = '';var pfdisableClickToDel = 1;var pfHideImages = 0;var pfImageDisplayStyle = 'left';var pfDisablePDF = 0;var pfDisableEmail = 0;var pfDisablePrint = 1;var pfCustomCSS = '';var pfBtVersion='1';(function(){var js, pf;pf = document.createElement('script');pf.type = 'text/javascript';if('https:' == document.location.protocol){js='https://pf-cdn.printfriendly.com/ssl/main.js'}else{js='http://cdn.printfriendly.com/printfriendly.js'}pf.src=js;document.getElementsByTagName('head')[0].appendChild(pf)})();</script><a href="http://www.printfriendly.com" style="color:#6D9F00;text-decoration:none;" class="printfriendly" onclick="window.print();return false;" title="Printer Friendly and PDF"><img style="border:none;" src="http://cdn.printfriendly.com/pf-button-both.gif" alt="Print Friendly and PDF"/></a>


    I would like all the fields on the form to be sent to the other page upon submit, without requiring to use 100 "$_POST" 's.


    What would I replace "theString" with in
    $theString = implode(';', $_POST); ?


    Thank you so much for all your help, and again my apologies for not providing all the relevant information
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,868
    Rep Power
    368
    you could use a loop?

    foreach ($_POST as $name=>$value) {
    $string .= "$name: $value"; // or
    <input type="hidden" name="$name" value="$value" />
    }
  14. #8
  15. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    Ok, without making us read hundreds of lines of code, what is it you actually want. You have pageA, with a big form. PageA posts back to itself, and when that happens $_POST will be a very large array. That's where our understanding of your problem ends. Why is that unacceptable? What do you want from that? Are any other pages involved?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    27
    Rep Power
    0

    Unhappy


    Originally Posted by ManiacDan
    Ok, without making us read hundreds of lines of code, what is it you actually want. You have pageA, with a big form. PageA posts back to itself, and when that happens $_POST will be a very large array. That's where our understanding of your problem ends. Why is that unacceptable? What do you want from that? Are any other pages involved?

    Thank you for your reply. pageA (with the big form) posts to pageB, and also emails the various fields.

    What I am looking for, is a way to post ALL the fields from pageA's form, onto pageB - without doing it one at a time as I have done with these

    Code:
    <tr><td>Last Name</td><td>".$_POST['lastName']."</td></tr>
                   <tr><td>Tel No</td><td>".$_POST['telNo']."</td></tr>
                   <tr><td>Cell No</td><td>".$_POST['cellNo']."</td></tr>
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,868
    Rep Power
    368
    Originally Posted by ultramel123
    Thank you for your reply. pageA (with the big form) posts to pageB, and also emails the various fields.

    What I am looking for, is a way to post ALL the fields from pageA's form, onto pageB - without doing it one at a time as I have done with these

    Code:
    <tr><td>Last Name</td><td>".$_POST['lastName']."</td></tr>
                   <tr><td>Tel No</td><td>".$_POST['telNo']."</td></tr>
                   <tr><td>Cell No</td><td>".$_POST['cellNo']."</td></tr>
    and i have given you a suggestion of using LOOPS..
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    10
    Rep Power
    0
    I could be wrong, but can't you use foreach statement for this?

    Example:
    PHP Code:
    foreach ($_POST as $name=>$value) {    
    echo (
    "<tr><td>".$name.": </td><td>".$value."</td></tr>"); 

  22. #12
  23. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    Ok, part of the problem comes from your misuse of the terms. These are the facts:

    1) PageA posts to PageA. Strider64 pointed out that your form's ACTION is blank. That means PageA posts back to itself.

    2) Sending form data to a script is called POST. Printing it is not called POST.

    3) You can use any of the various foreach loops to PRINT this data, as well as the implode command I gave earlier to turn the $_POST array into a string.

    4) You say you need to email this data, but also print it as an HTML table. Do the page and the email both have the same contents?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    27
    Rep Power
    0
    Originally Posted by paulh1983
    you could use a loop?

    foreach ($_POST as $name=>$value) {
    $string .= "$name: $value"; // or
    <input type="hidden" name="$name" value="$value" />
    }

    Thank you I have tried to do this but it's returning this error

    Parse error: syntax error, unexpected <' in /home/airportg/public_html/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()d code on line 29

    ( i copied it exactly as you suggested, perhaps I inserted the code in the incorrect place?)
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    27
    Rep Power
    0
    Originally Posted by ManiacDan
    Ok, part of the problem comes from your misuse of the terms. These are the facts:

    1) PageA posts to PageA. Strider64 pointed out that your form's ACTION is blank. That means PageA posts back to itself.

    2) Sending form data to a script is called POST. Printing it is not called POST.

    3) You can use any of the various foreach loops to PRINT this data, as well as the implode command I gave earlier to turn the $_POST array into a string.

    4) You say you need to email this data, but also print it as an HTML table. Do the page and the email both have the same contents?
    Thank you for your reply:
    1) This is my form action
    <form method="POST" id="quote" action="?page_id=2601.php">

    page_id=2601 is page B

    2) noted
    3)ok
    4)Yes, the email should contain exactly the same contents and layout as what is printed
  28. #15
  29. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    1) So it is, I assumed his copy/paste of code was...your code. I don't know what he was even saying anymore, so disregard that whole conversation

    4) Just use this:
    PHP Code:
    $str '<table border=1 cellpadding=3>';
    foreach ( 
    $_POST as $k => $v ) {
      
    $str .= "<tr><td><b>{$k}</b></td><td>{$v}</td></tr>";
    }
    $str .= '</table>'
    Then, $str will be a table containing everything in $_POST. Echo it, and also email it (getting HTML content to show up in an email is a whole other exercise though).
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
Page 1 of 3 123 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo