Only the name part is used for forms when passing data. The ID is used to uniquely identify elements for CSS and Javascript.

Only the name part is used for forms when passing data. The ID is used to uniquely identify elements for CSS and Javascript.
And frustratingly i've just realised it's case sensitive, bah
So i now have all the fields emailing me to look like the following:
Is there any way i can setup the code so that it comes out more like this:Student Name: 1
Tutor Group: 2
Staff Member: 3
Date of Incident: 4
Period: 5
Subject: 6
Student Name: qwerty -------------------- Tutor Group: 8C
Staff Member: qwerty --------------------- Date of Incident: 929294
Period: 3 --------------------------------- Subject: English
Where the "-"s are just blank space

Yes, in theory
Sending it as plaintext allows certain characters such as \n (newline) and \t (tab).
For example:
This has certain drawbacks that the values for $name etc will be of different and unknown lengths - resulting in some lines longer than others. Without some messy calculations (or generating an HTML email) I think that's the best you are likely to achieve.Code:$body = "Student name: $name \t\t Tutor Group: $tutor_group\n\n";
With HTML email you can format that data nicely in a table. If you want to do this, have a look at Example 4 on the mail() function documentation.
mrbios (30th June 2010)
Thank you very much, i'll go and have a play with that in a bit, time to refuel my brain with a sarnie![]()

You can add tab spaces in to your PHP code by adding '\t' (no quotes) anywhere in your strings, but it won't neccessarily work out how you want it to if a particularly long name is entered.
An alternative is to make the email that gets sent HTML.
First you need to add info to the email header to make it HTML. Add the following directly after you set the $headers variable:
Now simply write your $body variable as though it were HTML, using a table to get the layout how you want itCode:$headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
EDIT: webman beat me to it![]()

mrbios: Great idea about lunch!
LosOjos: Great minds think alike![]()
How does this look:
I've left the old body there and just commented it out for now, and changed the bit in mail() from $body to $message, i obviously still need to add in the content to the body, but apart from that is that correct?Code:<?php //If the form is submitted if(isset($_POST['submit'])) { $name = trim($_POST['Student']); $tutor = trim($_POST['TutorGroup']); $staff = trim($_POST['StaffMember']); $doi = trim($_POST['DateofIncident']); $period = trim($_POST['period']); $subject1 = trim($_POST['Subject1']); $C1 = trim($_POST['C1']); $C2 = trim($_POST['C2']); $C3 = trim($_POST['C3']); $C1Rule = trim($_POST['C1Rule']); $C2Rule = trim($_POST['C2Rule']); $C3Rule = trim($_POST['C3Rule']); $Signed = trim($_POST['Signed']); $Time = trim($_POST['Time']); $emailTo = 'mothj@archwayschool.net'; $subject="C3 Referral Form"; //Plain text email: $body = "Student Name: $name \n\n Tutor Group: $tutor \n\n Staff Member: $staff \n\n Date of Incident: $doi \n\n Period: $period \n\n Subject: $subject1 \n\n C1 Rule broken: $C1Rule \n\n C2 Rule Broken: $C2Rule \n\n C3 Rule Broken: $C3Rule \n\n C1 Explanation: $C1 \n\n C2 Explanation: $C2 \n\n C3 Explanation: $C3 \n\n Time sent to BFL: $Time \n\n Signed: $Signed \n\n"; $headers = "From: " . $emailTo . "\r\nReply-To: " . $emailTo; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $message = ' <html> <head> <title>C3 Referral Form</title> </head> <body> </body> </html> '; mail($emailTo, $subject, $message, $headers); $emailSent = true; } ?>

Looks OK.
When testing, to save on mailing each time, you could just do echo $message; to show it on the page instead, and comment out the mail() line.
Right i've created a new page, made myself a form with 3 tables, i've copied all the code from that page into the body section of my html email bit, now how do i declare the variables within the email? just put $name etc or is there more to it than that?

Like you had before - this bit:
When using single quotes you do it like this:Code:$message = ' <html> <head> <title>C3 Referral Form</title> </head> <body> </body> </html> ';
Code:$message = ' <html> .... <table> <tr><td>Name:</td><td>' . $name . '</td></tr> </table> </body> </html> ';
Only when using double quotes can you insert variables directly into the string.
For very long strings (like your $message will be) there's another method of doing it which might be helpful - heredoc.
Code:$message = <<<EOT <body> ... <td>Name:</td> <td>$name</td> ... EOT;
Last edited by webman; 30th June 2010 at 01:42 PM.
mrbios (30th June 2010)
Ok this is what i have now:
I could leave it as it is now as it's at the point where they could use it, but i want to do the following:Code:<?php //If the form is submitted if(isset($_POST['submit'])) { $name = trim($_POST['Student']); $tutor = trim($_POST['TutorGroup']); $staff = trim($_POST['StaffMember']); $doi = trim($_POST['DateofIncident']); $period = trim($_POST['period']); $subject1 = trim($_POST['Subject1']); $C1 = trim($_POST['C1']); $C2 = trim($_POST['C2']); $C3 = trim($_POST['C3']); $C1Rule = trim($_POST['C1Rule']); $C2Rule = trim($_POST['C2Rule']); $C3Rule = trim($_POST['C3Rule']); $Signed = trim($_POST['Signed']); $Time = trim($_POST['Time']); $emailTo = 'mothj@archwayschool.net'; $subject="C3 Referral Form"; //Plain text email: $body = "Student Name: $name \n\n Tutor Group: $tutor \n\n Staff Member: $staff \n\n Date of Incident: $doi \n\n Period: $period \n\n Subject: $subject1 \n\n C1 Rule broken: $C1Rule \n\n C2 Rule Broken: $C2Rule \n\n C3 Rule Broken: $C3Rule \n\n C1 Explanation: $C1 \n\n C2 Explanation: $C2 \n\n C3 Explanation: $C3 \n\n Time sent to BFL: $Time \n\n Signed: $Signed \n\n"; $headers = "From: " . $emailTo . "\r\nReply-To: " . $emailTo; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $message = ' <html> <head> <title>C3 Referral Form</title> </head> <body> <h1 align="center"><strong>C3 Referral Form</strong></h1> <table width="793" height="224" border="0"> <tr> <th width="123" height="74" scope="col"><div align="right">Name of Student:</div></th> <td width="259" scope="col">' . $name . '</td> <th width="114" scope="col"><div align="right">Tutor Group:</div></th> <td width="269" scope="col">' . $tutor . '</td> </tr> <tr> <th height="72" scope="row"><div align="right">Staff Member:</div></th> <td>' . $staff . '</td> <th><div align="right">Date of Incident:</div></th> <td>' . $doi . '</td> </tr> <tr> <th height="68" scope="row"><div align="right">Subject:</div></th> <td>' . $subject1 . '</td> <th><div align="right">Period:</div></th> <td>' . $period . '</td> </tr> </table> <p>Reasons why the warnings were given:</p> <table width="793" height="251" border="1"> <tr> <th width="59" scope="col"> </th> <th width="57" scope="col">Rule Broken</th> <th width="655" scope="col">Explanation of Incidents</th> </tr> <tr> <th scope="row">C1</th> <td>' . $C1Rule . '</td> <td>' . $C1 . '</td> </tr> <tr> <th scope="row">C2</th> <td>' . $C2Rule . '</td> <td>' . $C2 . '</td> </tr> <tr> <th scope="row">C3</th> <td>' . $C3Rule . '</td> <td>' . $C3 . '</td> </tr> </table> <p> </p> <table width="630" height="114" border="0"> <tr> <th width="212" scope="col"><div align="right">Exact time sent to BfL Centre:</div></th> <td>' . $Time . '</td> </tr> <tr> <th scope="row"><div align="right">Signed:</div></th> <td>' . $Signed . '</td> </tr> </table> <p> </p> </body> </html> '; mail($emailTo, $subject, $message, $headers); $emailSent = true; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>C3 Referral Form</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> <script src="jquery.validate.pack.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function(){ $("#contactform").validate(); }); </script> <style type="text/css"> body { font-family:Arial, Tahoma, sans-serif; } #contact-wrapper { width:880px; border:1px solid #e2e2e2; background:#f1f1f1; padding:20px; } #contact-wrapper div { clear:both; margin:1em 0; } #contact-wrapper label { display:block; float:none; font-size:16px; width:auto; } form#contactform input { border-color:#B7B7B7 #E8E8E8 #E8E8E8 #B7B7B7; border-style:solid; border-width:1px; padding:5px; font-size:16px; color:#333; } form#contactform textarea { font-family:Arial, Tahoma, Helvetica, sans-serif; font-size:100%; padding:0.6em 0.5em 0.7em; border-color:#B7B7B7 #E8E8E8 #E8E8E8 #B7B7B7; border-style:solid; border-width:1px; } </style> </head> <body> <h1 align="center"><u>C3 Referral Form</u></h1> <p align="center">This form is to be completed if a student chooses to be sent to the BfL Centre and <strong>MUST BE COMPLETED THE SAME DAY.</strong></p> <div id="contact-wrapper"> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" id="contactform"> <div style="width:400px"> <label for="Name of Student"><strong>Name of Student:</strong></label> <input type="text" size="50" name="Student" id="Student" value="" /> </div> <div style="width:400px"> <label for="Tutor Group"><strong>Tutor Group:</strong></label> <input type="text" size="50" name="TutorGroup" id="Tutorgroup" value="" /> </div> <div style="width:400px"> <label for="Staff Member"><strong>Staff Member:</strong></label> <input type="text" size="50" name="StaffMember" id="StaffMember" value="" /> </div> <div style="width:400px"> <label for="Date of Incident"><strong>Date of Incident:</strong></label> <input type="text" size="50" name="DateofIncident" id="Dateofincident" value="" /> </div> <div style="width:400px"> <label for="Period"><strong>Period:</strong></label> <input type="text" size="50" name="period" id="period" value="" /> </div> <div style="width:400px"> <label for="Subject"><strong>Subject:</strong></label> <input type="text" size="50" name="Subject1" id="Subject1" value="" /> </div> <table width="740" height="227" border="1"> <tr> <th width="40" height="62" scope="col"> </th> <th width="59" scope="col">Rule Broken</th> <th width="619" scope="col">Explanation of Incident</th> </tr> <tr> <th height="89" scope="row">C1</th> <td><textarea name="C1Rule" cols="10" rows="5" id="C1 Rule Broken"></textarea></td> <td> <textarea name="C1" cols="100" rows="5" id="C1 Explanation"></textarea> </td> </tr> <tr> <th scope="row">C2</th> <td><textarea name="C2Rule" cols="10" rows="5" id="C2 Rule Broken"></textarea></td> <td><textarea name="C2" cols="100" rows="5" id="C2 Explanation"></textarea></td> </tr> <tr> <th scope="row">C3</th> <td><textarea name="C3Rule" cols="10" rows="5" id="C3 Rule Broken"></textarea></td> <td><textarea name="C3" cols="100" rows="5" id="C3 Explanation"></textarea></td> </tr> </table> <div style="width:400px"> <label for="Exact Time sent to BFL"><strong>Exact time sent to BfL:</strong></label> <input type="text" size="50" name="Time" id="TimeSenttoBFL" value="" /> </div> <div> <label for="Signed"><strong>Signed:</strong></label> <input type="text" size="50" name="Signed" id="Signed" value="" /> </div> <p> <input type="submit" value="Submit C3" name="submit" /> </p> </form> </div> </body> </html>
On the form itself (going away from the email bit for a moment) i'd like to have Two boxes on one line, im not sure how to achive this? doing it the dumb person way of dragging the box and plonking it next to the other one just makes it squash next to the other one

I always find tables the easiest way to format HTML, just give them invisible borders so they don't ruin your layout
Morning, i have another issue, hopefully just a simple fix this time...
If i have check boxes when checked and submitted to email they say "on" or are just blank, is there a way to change this "on" to "yes" ?
EDIT: never mind, that was incredibly simple, i blame the fact it's morning
Last edited by mrbios; 1st July 2010 at 09:23 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)