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

Thread: php POST

  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    19
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Question php POST

    Hi

    I am posting the values from a form on page A, to page B, using the following code.

    The problem is, that I would like to display the form field "labels" rather than the field "names"

    I have tried to get around this problem by making the first letter of each word (field name) uppercase, and also to replace the underscore with spaces. This makes the field names more readable on the page when posted.

    However I cannot change all the field names to what the labels are, as some o them are being used in calculations.

    eg: field label: "Amount of Delegates 1/2 Day Conference"
    field name: "halfday1"

    is there a way for this to POST the field labels along with the value, rather than the field names, along with the value.
    I hope my question is clear - I have tried to explain it as best I can

    Thank you


    page B:

    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";
       
    $str =      '<table border=1 cellpadding=3 width="500">'
                   foreach ( 
    $_POST as $k => $v ) { 
                   
    $k str_replace('_'' '$k); 
                   
    $k ucwords($k);
                   
    $str .= "<tr><td><b>{$k}</b></td><td>{$v}</td></tr>";
                   } 
                   
    $str .= '</table>';
           if(
    mail($to$subject$str$headers)){  
           echo 
    "Message sent successfully...<br />"
           echo 
    $str;
           }else{
           echo 
    'Error! try again';
        }
    }
    ?>

    page A: http://jsfiddle.net/FRY45/

  • #2
    Regular Coder
    Join Date
    Jun 2009
    Posts
    138
    Thanks
    3
    Thanked 19 Times in 19 Posts
    The answer is no, labels are not transmitted..

    Why dont you just have the head table line like you do in the first place inserted in the second page that will be emailed??

    PHP Code:
    $str =      '<table border=1 cellpadding=3 width="500">
    <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>
    '

    Or if I have got this all wrong and you arent wanting them for display in the email you could instead gather them via including hidden post items that display them

    PHP Code:
    <input type="hidden" name=""label_halfday1" value="Amount of Delegates 1/2 Day Conference"> 

  • #3
    New Coder
    Join Date
    Oct 2011
    Posts
    19
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Thank you so much for your reply.

    in the first section of your post, if I use the headline values, how would I then include the values of ".$_POST." to go with the labels?

  • #4
    Regular Coder
    Join Date
    Jun 2009
    Posts
    138
    Thanks
    3
    Thanked 19 Times in 19 Posts
    I didnt take much notice of your foreach loop, I will just write up a better solution now..

  • Users who have thanked itxtme for this post:

    Melissafleet (05-09-2013)

  • #5
    Regular Coder
    Join Date
    Jun 2009
    Posts
    138
    Thanks
    3
    Thanked 19 Times in 19 Posts
    Your problem is the way in which you are processing your post variables.

    You say that the fields will not change much. My suggestion is to move away from your foreach loop which is creating a table with no resemblance of your original..

    what you want to do is out put each line of your form (which is static you are saying) into your table..

    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";
       
       
    //Add the order info
       
    $str "Enquiry Date: {$_POST['enquiry_date']}<br>
                  Conference Name: {$_POST['conference_Name']}"
    ;
               
    //!! You would need to add all of your contact variables, cant have me do all of the work for you!!!
       
       // Create the pretty(er) table
       
    $str .= '<table border=1 cellpadding=3 width="500">
               <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>'
    ;
      
    // Now lets add all the table data
          //Week1
      
    $str .= "<tr>
                  <td>{$_POST['day_11']}</td>
                <td>{$_POST['halfday1']}</td>
                <td>{$_POST['fullday1']}</td>
                <td>{$_POST['MenuNo1']}</td>
                <td>{$_POST['MenuPrice1']}</td>
                <td>{$_POST['MealPersons1']}</td>
                <td>{$_POST['SingleRooms1']}</td>
                <td>{$_POST['DoubleRooms1']}</td>
                <td>{$_POST['total1']}</td>
              </tr>"
    ;
              
        
    //Week2
        
        //Week3 .. and so on - you need to do these!!
              
      // Time to close the table
      
    $str .= '</table>';
      
    //Email the order
           
    if(mail($to$subject$str$headers)){  
           echo 
    "Message sent successfully...<br />"
           echo 
    $str;
           }else{
           echo 
    'Error! try again';
        }
    }
    ?>

  • Users who have thanked itxtme for this post:

    Melissafleet (05-09-2013)

  • #6
    New Coder
    Join Date
    Oct 2011
    Posts
    19
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Smile

    Quote Originally Posted by itxtme View Post
    Your problem is the way in which you are processing your post variables.

    You say that the fields will not change much. My suggestion is to move away from your foreach loop which is creating a table with no resemblance of your original..

    what you want to do is out put each line of your form (which is static you are saying) into your table..

    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";
       
       
    //Add the order info
       
    $str "Enquiry Date: {$_POST['enquiry_date']}<br>
                  Conference Name: {$_POST['conference_Name']}"
    ;
               
    //!! You would need to add all of your contact variables, cant have me do all of the work for you!!!
       
       // Create the pretty(er) table
       
    $str .= '<table border=1 cellpadding=3 width="500">
               <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>'
    ;
      
    // Now lets add all the table data
          //Week1
      
    $str .= "<tr>
                  <td>{$_POST['day_11']}</td>
                <td>{$_POST['halfday1']}</td>
                <td>{$_POST['fullday1']}</td>
                <td>{$_POST['MenuNo1']}</td>
                <td>{$_POST['MenuPrice1']}</td>
                <td>{$_POST['MealPersons1']}</td>
                <td>{$_POST['SingleRooms1']}</td>
                <td>{$_POST['DoubleRooms1']}</td>
                <td>{$_POST['total1']}</td>
              </tr>"
    ;
              
        
    //Week2
        
        //Week3 .. and so on - you need to do these!!
              
      // Time to close the table
      
    $str .= '</table>';
      
    //Email the order
           
    if(mail($to$subject$str$headers)){  
           echo 
    "Message sent successfully...<br />"
           echo 
    $str;
           }else{
           echo 
    'Error! try again';
        }
    }
    ?>


    Thank you !!!!!!!!!!!! This is working beautifully ! It is absolutely perfect ! Thank you kindly for the time taken to assist me, I appreciate it tremendously :-)


  •  

    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
    •