+ Post New Thread
Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28
Web Development Thread, Creating a form, web novice, help please in Coding and Web Development; Only the name part is used for forms when passing data. The ID is used to uniquely identify elements for ...
  1. #16

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,417
    Thank Post
    644
    Thanked 965 Times in 665 Posts
    Blog Entries
    2
    Rep Power
    328
    Only the name part is used for forms when passing data. The ID is used to uniquely identify elements for CSS and Javascript.

  2. #17
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,611
    Thank Post
    374
    Thanked 270 Times in 222 Posts
    Rep Power
    103
    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:
    Student Name: 1

    Tutor Group: 2

    Staff Member: 3

    Date of Incident: 4

    Period: 5

    Subject: 6
    Is there any way i can setup the code so that it comes out more like this:

    Student Name: qwerty -------------------- Tutor Group: 8C

    Staff Member: qwerty --------------------- Date of Incident: 929294

    Period: 3 --------------------------------- Subject: English

    Where the "-"s are just blank space

  3. #18

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,417
    Thank Post
    644
    Thanked 965 Times in 665 Posts
    Blog Entries
    2
    Rep Power
    328
    Yes, in theory

    Sending it as plaintext allows certain characters such as \n (newline) and \t (tab).

    For example:

    Code:
    $body = "Student name: $name \t\t Tutor Group: $tutor_group\n\n";
    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.

    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.

  4. Thanks to webman from:

    mrbios (30th June 2010)

  5. #19
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,611
    Thank Post
    374
    Thanked 270 Times in 222 Posts
    Rep Power
    103
    Thank you very much, i'll go and have a play with that in a bit, time to refuel my brain with a sarnie

  6. #20

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,664
    Thank Post
    1,484
    Thanked 1,263 Times in 857 Posts
    Rep Power
    803
    Quote Originally Posted by mrbios View Post
    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: qwerty -------------------- Tutor Group: 8C

    Staff Member: qwerty --------------------- Date of Incident: 929294

    Period: 3 --------------------------------- Subject: English

    Where the "-"s are just blank space
    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:
    Code:
    $headers .= 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    Now simply write your $body variable as though it were HTML, using a table to get the layout how you want it


    EDIT: webman beat me to it

  7. #21

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,417
    Thank Post
    644
    Thanked 965 Times in 665 Posts
    Blog Entries
    2
    Rep Power
    328
    mrbios: Great idea about lunch!

    LosOjos: Great minds think alike

  8. #22
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,611
    Thank Post
    374
    Thanked 270 Times in 222 Posts
    Rep Power
    103
    How does this look:
    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;
    	}
    ?>
    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?

  9. #23

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,417
    Thank Post
    644
    Thanked 965 Times in 665 Posts
    Blog Entries
    2
    Rep Power
    328
    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.

  10. #24
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,611
    Thank Post
    374
    Thanked 270 Times in 222 Posts
    Rep Power
    103
    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?

  11. #25

    webman's Avatar
    Join Date
    Nov 2005
    Location
    North East England
    Posts
    8,417
    Thank Post
    644
    Thanked 965 Times in 665 Posts
    Blog Entries
    2
    Rep Power
    328
    Like you had before - this bit:

    Code:
    $message = '
    		<html>
    		<head>
    			<title>C3 Referral Form</title>
    		</head>
    		<body>
    		
    		</body>
    		</html>
    		';
    When using single quotes you do it like this:

    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 02:42 PM.

  12. Thanks to webman from:

    mrbios (30th June 2010)

  13. #26
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,611
    Thank Post
    374
    Thanked 270 Times in 222 Posts
    Rep Power
    103
    Ok this is what i have now:

    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">&nbsp;</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>&nbsp;</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>&nbsp;</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">&nbsp;</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>
    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:
    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

  14. #27

    LosOjos's Avatar
    Join Date
    Dec 2009
    Location
    West Midlands
    Posts
    5,664
    Thank Post
    1,484
    Thanked 1,263 Times in 857 Posts
    Rep Power
    803
    I always find tables the easiest way to format HTML, just give them invisible borders so they don't ruin your layout

  15. #28
    mrbios's Avatar
    Join Date
    Jun 2007
    Location
    Stroud, Gloucestershire
    Posts
    2,611
    Thank Post
    374
    Thanked 270 Times in 222 Posts
    Rep Power
    103
    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 10:23 AM.



SHARE:
+ Post New Thread
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Sharepoint Contact form web parts
    By paul_1989 in forum Web Development
    Replies: 3
    Last Post: 29th March 2010, 12:20 AM
  2. fill web form from excel
    By RabbieBurns in forum How do you do....it?
    Replies: 0
    Last Post: 8th October 2008, 02:17 PM
  3. Web-based contact form being abused
    By HodgeHi in forum Web Development
    Replies: 17
    Last Post: 5th November 2007, 12:29 PM
  4. Web form
    By Halfmad in forum Web Development
    Replies: 12
    Last Post: 2nd May 2007, 01:16 PM
  5. Creating a form in frontpage2003
    By park_bench in forum Web Development
    Replies: 2
    Last Post: 24th January 2007, 10:18 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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