Problems with Form submitting (HTML/PHP)

apulaiset

New Member
Messages
5
Reaction score
0
Points
0
Ok, so I will not act like I know what I am talking about because I am a complete noob to scripting, and after spending 7 hrs to try to find the fix myself, i'll ask for some help.

I have done this form submit website for a form (HTML), and I am wondering how to get the formsubmit script (php) to send the information to me in the same format as the website. We are trying to get rid of all this useless paperwork stuff, but would like the same format as the website. It sends it already but sorts the data into a t-chart list, and we would like it to be sent in the format that it is filled out in on the website. I don't even know if this is possible..... I hope it is!

Here are the two files. I attached them and just added ".txt" to them both. If someone could help me i would really appreciate it. I know how to fake things ok, but nothing serious like figuring this thing out....
 

Attachments

  • report.html.txt
    9.1 KB · Views: 96
  • submit.php.txt
    14.8 KB · Views: 194

freecrm

New Member
Messages
629
Reaction score
0
Points
0
You're in for a bit of a challenge then!

It is possible to send html from a php scripted form.

What you need to do is set up the php form as you normally would with form submit taking you to another php page.

2nd page will assign the values from each form field to a variable.

i.e.

<?php
$name=$_POST['name'];
$contactemail=$_POST['email'];
?>

You don't have to do this but it makes life easier later on.

once you have a list of variables set, you can set up the e-mail function.

<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= 'From: you(you@whatever.com)' . "\r\n";
$headers .= 'Reply-To: you@whatever.com' . "\r\n";
$headers .= 'Return-Path:'.$contactemail. "\r\n";
$headers .= 'X-Sender: '.$contactemail. "\r\n";
$headers .= 'X-Mailers: PHP /'.phpversion() . "\r\n";

$subject = "Subject - Something";

$message = '
<html>
<body>
<font size="2" face="Arial">
<p>Dear '.$firstname.' '.$lastname.',</p>
<p>This is standard html with 2 variables shown.</p>
</font>
</body>
</html>

';

ini_set(sendmail_from,$contactemail);

if (@mail(''.$firstname.' '.$lastname.'<'.$contactemail.'>',stripslashes($subject),stripslashes($message),stripslashes($headers)))
{
echo ('
<p>e-mail successfully sent to '. $contactemail . '</p>
');
}
else
{
echo ('
<p>Error! The e-mail has failed to send to ' . $contactemail . '. Please try again.</p>
');
}
ini_restore( sendmail_from );
?>

I've put the standard html in blue with the inserted php variables in black.

Hopes this gives you a bit of a start.
 
Last edited:

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
So, taking a look at your 2 pages, do you want the form results emailed to you, or do you want it saved into a database?
 

apulaiset

New Member
Messages
5
Reaction score
0
Points
0
Yes, what I would like is to have the full out form sent to me with the results in the spots. The problem is I have tried the whole " $message = ' <html> " and all it sent was a blank email. So I am wondering what the exact code would be. Right now I have from the php script: (I'll use the --- to seperate things)
-----------------------------------------------
// mail the content we figure out in the following steps
function mail_it($content, $subject, $email, $recipient) {
global $attachment_chunk, $attachment_name, $attachment_type, $attachment_sent, $bcc;

$ob = "----=_OuterBoundary_000";
$ib = "----=_InnerBoundery_001";

$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: ".$email."\n";
$headers .= "To: ".$recipient."\n";
$headers .= "Reply-To: ".$email."\n";
if ($bcc) $headers .= "Bcc: ".$bcc."\n";
$headers .= "X-Priority: 1\n";
$headers .= "X-Mailer: DT Formmail".VERSION."\n";
$headers .= "Content-Type: multipart/mixed;\n\tboundary=\"".$ob."\"\n";


$message = "This is a multi-part message in MIME format.\n";
$message .= "\n--".$ob."\n";
$message .= "Content-Type: multipart/alternative;\n\tboundary=\"".$ib."\"\n\n";
$message .= "\n--".$ib."\n";
$message .= "Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n\n";
$message .= $content."\n\n";
$message .= "\n--".$ib."--\n";
if ($attachment_name && !$attachment_sent) {
$message .= "\n--".$ob."\n";
$message .= "Content-Type: $attachment_type;\n\tname=\"".$attachment_name."\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: attachment;\n\tfilename=\"".$attachment_name."\"\n\n";
$message .= $attachment_chunk;
$message .= "\n\n";
$attachment_sent = 1;
}
$message .= "\n--".$ob."--\n";

mail($recipient, $subject, $message, $headers);

}

---------------------------------------
And that sends me the results looking like:
----------------------------------------
Name_of_Missionary: 0
Name_of_Companion: 0
Proselyting_Area: 0
Reporting_Period: 0
Phone_number: 0
Zone: 0
District: 0
Baptized: 0
Confirmed: 0
Committed: 0
Invstgtrs_at_Sacrament: 0
Lessons_with_member: 00
Other_lessons: 0
Progressing_Investigators: 0
Referrals_Recieved: 0
Referrals_contacted: 0
New_investigators: 0
Lessons_taught_to_RC_LA: 0
Hours_Tracting: 0
Hours_Contacting: 0
Other_Investigators: 0
SYL_Days: 0
Letter_to_President: 0

---------------------------------------------

But what I don't understand is how it sorts the results, and if there is a way, could that all be set back into the original html form/table format I have when it is sent.

so how would I insert the html into the PHP???

here is the html I would like to insert for easyness:
------------------------------------------------------
<html>

<body>

<form method="POST" action="submit.php" onSubmit="return validator(this)">

<center>


<h1>Missionary Weekly Report</h1>
</center>

<table width="100%" cellpadding="2" cellspacing="0">
<tr>
<td>Name of missionary</td><td><input type="text" name="Name_of_Missionary" size="22"></td>

<td>Name of companion</td><td><input type="text" name="Name_of_Companion" size="20"></td>

<td>Proselyting area</td><td colspan="3"><input type="text" name="Proselyting_Area" size="50"></td>
</tr>
<tr>

<td>Reporting period</td><td><input type="text" name="Reporting_Period" size="20"></td>

<td>Phone number</td><td><input type="text" name="Phone_number" size="14"></td>

<td>Zone</td><td><input type="text" name="Zone" size="17"></td>

<td>District</td><td><input type="text" name="District" size="16"></td>
</tr>
</table>


<br>
<center><font size="4"><b>Key Indicators</b></font></center>


<table width="100%" cellpadding="2" cellspacing="0">

<tr>

<td align="center" colspan="2">Investigators baptized and confirmed</td>

<td align="center" rowspan="2">Investigators with a baptismal date</td>

<td align="center" rowspan="2">Investigators who attend sacrament meeting</td>

<td align="center" rowspan="2">Lessons taught to investigators with a member</td>

<td align="center" rowspan="2">Other lessons taught</td>

<td align="center" rowspan="2">*Progressing investigators</td>

<td align="center" colspan="2">Referrals</td>

<td align="center" rowspan="2">New investigators</td>

<td align="center" rowspan="2">Lessons taught to recent converts and less-active members</td>

<td align="center" rowspan="2">Hours spent Tracting</td>

<td align="center" rowspan="2">Hours spent Contacting</td>

<td align="center" rowspan="2">Other Investigators</td>

<td align="center" rowspan="2">SYL Days</td>

</tr>

<tr>

<td align="center">Baptized</td>

<td align="center">Confirmed</td>

<td align="center">Received</td>

<td align="center">Contacted</td>

</tr>

<tr>

<td align="center"><input type="text" name="Baptized" size="2"></td>

<td align="center"><input type="text" name="Confirmed" size="2"></td>

<td align="center"><input type="text" name="Committed" size="2"></td>

<td align="center"><input type="text" name="Invstgtrs_at_Sacrament" size="2"></td>

<td align="center"><input type="text" name="Lessons_with_member" size="2"></td>

<td align="center"><input type="text" name="Other_lessons" size="2"></td>

<td align="center"><input type="text" name="Progressing_Investigators" size="2"></td>

<td align="center"><input type="text" name="Referrals_Recieved" size="2"></td>

<td align="center"><input type="text" name="Referrals_contacted" size="2"></td>

<td align="center"><input type="text" name="New_investigators" size="2"></td>

<td align="center"><input type="text" name="Lessons_taught_to_RC_LA" size="2"></td>

<td align="center"><input type="text" name="Hours_Tracting" size="2"></td>

<td align="center"><input type="text" name="Hours_Contacting" size="2"></td>

<td align="center"><input type="text" name="Other_Investigators" size="2"></td>

<td align="center"><input type="text" name="SYL_Days" size="2"></td>

</tr>

</table>

<font size="2">

<div width="500">
*Progressing investigators: Investigators who have been taught two or more times and are keeping their commitments to read the Book of Mormon and pray about it and the Prophet Joseph Smith, to attend church, and so on.<br>
</font>

<br>

<center>

<h3>Letter to the Mission President</h3>

<div style="width:800px; text-align: left;">

<font size="2">
Describe your efforts in helping your investigators prepare to receive the ordinances of baptism and confirmation. Describe work with recent converts and less-active members. Also describe how your gospel study is helping you, and add any personal concerns.
</font>
</div>

<textarea name="Letter_to_President" style="width:800px;height:400px;"></textarea>
<br><br>

</form>

</body>

</html>

-------------------------------------------------

And what would I need to change in the HTML iteself to have the results appear instead of just having blank spots???

Any help is appriciated. It really is!
 

Salvatos

Member
Prime Account
Messages
562
Reaction score
1
Points
18
Well as a proofreader I first noticed this:
$ob = "----=_OuterBoundary_000";
$ib = "----=_InnerBoundery_001";
which is probably a typo. But for the rest I don't know enough to help you, sorry.
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
OK - I just had a quick look at your submit.php file ???

It's missing the php opener and closer.

i.e. - it has no "<?php" opener and there is a "?>" missing at the end of the script.

Do you actually need to use a third party? If not, making your own is much simpler, more effective and has better control.
Edit:
I've noticed something strange going on in this area:

Please use your browser's back button to return to the form and try again.<?
}
} else { // every other error
?>
The form was not submitted because of the following reasons:<p>
Jack's Formmail.php ".VERSION."</a></small>\n\n";

exit;
}

// function to check the banlist
// suggested by a whole lot of people.. Thanks
function check_banlist($banlist, $email) {

I opened the file in Dreamweaver and I noticed that there is a closer (marked in red) but the following code is php and there is no opening "<?" or echo statement...
 
Last edited:

apulaiset

New Member
Messages
5
Reaction score
0
Points
0
Yeah, I really don't know too much. This is just a formmail script I got from off the internet. Another guy forwarded me to it because it is "easy" to use. So it is all freely done. the submit.php.txt is the full php script up in my first post. I think in it there is everything, I just copied the mail_it() function part out so someone could again "easily" put the html into the php, but I guess it isn't that easy.... :dunno:

Well if anyone reads this and know how to do the html into the php I still need help, I guess I just need to try to figure it out again.... it didn't work at all last time, but I guess there it is worth another try...
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
If you want to do a simpler system, you can always use the idea I suggested originally.

All you need is the original form and a form processing page with mail function.

The mail function will contain all the variables captured from the form.

1stly, there will be no changes to the orginal layout of the form, as these will be picked up in page 2.

Page 2 will capture all the form fields and put them into variables as follows.

<?php
$formfield1=$_POST['formfield1'];
$formfield2=$_POST['formfield2'];
$formfield3=$_POST['formfield3'];
?>

You can assign as many post variables as you want.

Further down the page, you can format your mail headers and mail script, which, in its most basic form is as follows:

<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= 'From: you(you@whatever.com)' . "\r\n";
$headers .= 'Reply-To: you@whatever.com' . "\r\n";
$headers .= 'Return-Path:'.$contactemail. "\r\n";
$headers .= 'X-Sender: '.$contactemail. "\r\n";
$headers .= 'X-Mailers: PHP /'.phpversion() . "\r\n";

$subject = "Subject - Something";

$message = '
<html>
<body>
Some Content
</body>
</html>
';

ini_set(sendmail_from,$contactemail);

if (@mail(''.$firstname.' '.$lastname.'<'.$contactemail.'>',stripslashes($su bject),stripslashes($message),stripslashes($header s)))
{
echo ('
<p>e-mail successfully sent to '. $contactemail . '</p>
');
}
else
{
echo ('
<p>Error! The e-mail has failed to send to ' . $contactemail . '. Please try again.</p>
');
}
ini_restore( sendmail_from );
?>


Then you just have the message to resolve.

Just copy the entire html and put it in where I have put Some content.

Finally, we just have to insert the posted variables into the html in the message.

To do this, you need to make a break in the code by inserting:
'.(the php variable).'

As an example, you could have an html table:

<table>
<tr>
<td>Result from first form field</td>
<td>'.$formfield1.'</td>
</tr>
<tr>
<td>Result from 2nd form field</td>
<td>'.$formfield2.'</td>
</tr>
<tr>
<td>Result from 3rd form field</td>
<td>'.$formfield3.'</td>
</tr>
</table>

The whole script for the 2nd page would therefore be:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form processing script</title>

<?php
$contactemail=$_POST['formfieldemail'];
$formfield1=$_POST['formfield1'];
$formfield2=$_POST['formfield2'];
$formfield3=$_POST['formfield3'];
?>
</head>
<body>
<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= 'From: you(you@whatever.com)' . "\r\n";
$headers .= 'Reply-To: you@whatever.com' . "\r\n";
$headers .= 'Return-Path:'.$contactemail. "\r\n";
$headers .= 'X-Sender: '.$contactemail. "\r\n";
$headers .= 'X-Mailers: PHP /'.phpversion() . "\r\n";

$subject = "Subject - Something";

$message = '
<html>
<body>
<table>
<tr>
<td>Result from first form field</td>
<td>'.$formfield1.'</td>
</tr>
<tr>
<td>Result from 2nd form field</td>
<td>'.$formfield2.'</td>
</tr>
<tr>
<td>Result from 3rd form field</td>
<td>'.$formfield3.'</td>
</tr>
</table>
</body>
</html>
';

ini_set(sendmail_from,$contactemail);

if (@mail('<'.$contactemail.'>',stripslashes($subject),stripslashes($message),stripslashes($headers)))
{
echo ('
<p>e-mail successfully sent to '. $contactemail . '</p>
');
}
else
{
echo ('
<p>Error! The e-mail has failed to send to ' . $contactemail . '. Please try again.</p>
');
}
ini_restore( sendmail_from );
?>
</body>
</html>


If you desperately want to cling to the complex pre-made script you are trying to adapt - good luck! :)
 

apulaiset

New Member
Messages
5
Reaction score
0
Points
0
Thanks for the help. After the last post I tried to get it to work, and while looking for a fix because I got it to send the HTML email, but couldn't get it to insert the data for some reason. But I fixed all of that, when I found http://www.tectite.com

It is a formmail that actually has an option to have a html template, and so I got that working.

Thanks for all the help!
 

chappill

New Member
Messages
74
Reaction score
0
Points
0
Here's the HTML code for a contact form on one of my other sites:

<form method="post">
Name:
<input name="name" type="text" id="name" size="50"><br>
E-mail:
<input name="email" type="text" id="email" size="50"><br>
Detail:
<input name="detail" type="text" id="detail" size="50"><br>
<input type="submit" name="Submit" value="Submit">
</form>

And here's the PHP code for it:
PHP:
<?php
$message="$detail";
$mail_from="$email";
$header="from: $name <$mail_from>";
$to ='youremail@whateverhere.com';
$send_contact=mail($to,$subject,$message,$header);
if($send_contact){
echo "Thank you, we've recieved you're reading request =D";
}
else {
echo "Error, please try again =[";
}
?>

Why don't people use simple stuff like that? Maybe add a captcha and a function so the form can't be submitted when the boxes are empty but that takes maybe 2-3 minutes.
 
Top