Jump to content


Hacked Emailhandler snippet - now has bugs


5 replies to this topic

#1 ikonia

    Etomite Forum Fan

  • Member
  • Pip
  • 117 posts

Posted 13 December 2007 - 10:03 AM

ok guys, I've hacked the "EmailHandler" snippet to look like this.

$sendemail =
isset($_POST['sendemail']) && $_POST['sendemail']!= "{{" && $_POST['sendemail']!= "[[" &&
$_POST['sendemail']!= "[(" && $_POST['sendemail']!= "[~" && $_POST['sendemail']!= "[*" ?
$_POST['sendemail'] : "";

$name =
isset($_POST['name']) && $_POST['name']!= "{{" && $_POST['name']!= "[[" &&
$_POST['name']!= "[(" && $_POST['name']!= "[~" && $_POST['name']!= "[*" ?
$_POST['name'] : "";

$email =
isset($_POST['email']) && $_POST['email']!= "{{" && $_POST['email']!= "[[" &&
$_POST['email']!= "[(" && $_POST['email']!= "[~" && $_POST['email']!= "[*" ?
$_POST['email'] : "";

//$subject =
//isset($_POST['subject']) && $_POST['subject']!= "{{" && $_POST['subject']!= "[[" &&
//$_POST['subject']!= "[(" && $_POST['subject']!= "[~" && $_POST['subject']!= "[*" ?
//$_POST['subject'] : "";

$telno =
isset($_POST['telno']) && $_POST['telno']!= "{{" && $_POST['telno']!= "[[" &&
$_POST['telno']!= "[(" && $_POST['telno']!= "[~" && $_POST['telno']!= "[*" ?
$_POST['telno'] : "";

$reqdate =
isset($_POST['reqdate']) && $_POST['reqdate']!= "{{" && $_POST['reqdate']!= "[[" &&
$_POST['reqdate']!= "[(" && $_POST['reqdate']!= "[~" && $_POST['reqdate']!= "[*" ?
$_POST['reqdate'] : "";

$reqtime =
isset($_POST['reqtime']) && $_POST['reqtime']!= "{{" && $_POST['reqtime']!= "[[" &&
$_POST['reqtime']!= "[(" && $_POST['reqtime']!= "[~" && $_POST['reqtime']!= "[*" ?
$_POST['reqtime'] : "";

$attend =
isset($_POST['attend']) && $_POST['attend']!= "{{" && $_POST['attend']!= "[[" &&
$_POST['attend']!= "[(" && $_POST['attend']!= "[~" && $_POST['attend']!= "[*" ?
$_POST['attend'] : "";






// check errors
$pattern = ".+@.+..+";
$error = '<font color="#FF0000">Required</font><br>';
$bad_email = '<font color="#FF0000">Make sure that you have entered a valid e-mail address.</font><br>';
if($sendemail=="sendemail"){
  if($name==""){$name_error = $error;}
  if($email==""){$email_error = $error;}
  elseif(!eregi($pattern,$email)){$email_error = $bad_email;}
  //if($subject==""){$subject_error = $error;}
  if($telno==""){$telno_error = $error;}
  if($reqdate==""){$reqdate_error = $error;}
  if($reqtime==""){$reqtime_error = $error;}
  if($attend==""){$attend_error = $error;}


}

if(($name!="")&&(eregi($pattern,$email))&&($telno!="")&&($reqdate!="")&&($reqtime!="")&&($attend!="")){
  $mail_message = "You have recieved an online booking request from $name\nFor a table on $reqdate at $reqtime for $attend people\n $name can be contacted on Telephone $telno and email address $email Please contact to confirm this booking";
  if($_SERVER["HTTP_HOST"] != "benreeves"){mail($to, 'Jacks Web Booking', $mail_message, 'From: test@localhost);}
  $EmailHandler = "<p>Thank you for requesting a reservation.</p><p>Please note that your booking is not confirmed until we contact you to do so. If you would ike to contact us directly, wel look forward to hearing from you on our phone number.</p>";
} else {
  $EmailHandler .= "<p>If you would like to contact us regarding a reservation, please use the form below, filling in all of the details. Please note that your booking is not confirmed until we contact you to do so. If you would like to contact us directly, please do so on 01249 700100 </p>";
  $EmailHandler .= '<form name="EmailHandler" action="" method="post">';
  $EmailHandler .= '<input name="sendemail" type="hidden" value="sendemail">';
  $EmailHandler .= '<p>'.$name_error.'<b>Your Name:</b><br><input type="text" name="name" class="text" value="'.$name.'">';
  $EmailHandler .= '<p>'.$email_error.'<b>Your E-mail Address:</b><br><input type="text" name="email" class="text" value="'.$email.'">';
  $EmailHandler .= '<p>'.$telno_error.'<b>Contact Telephone Number:</b><br><input type="text" name="telno" >'.$telno.'</input>';
  $EmailHandler .= '<p>'.$reqdate_error.'<b>Required Date:</b><br><input type="text" name="reqdate">'.$reqdate.'</input>';
$EmailHandler .= '<p>'.$reqtime_error.'<b>Required Time:</b><br><input type="text" name="reqtime" >'.$reqtime.'</input>';
$EmailHandler .= '<p>'.$attend_error.'<b>Number Of Attendees:</b><br><input type="text" name="attend">'.$reqtime.'</input>';
$EmailHandler .= '<p><b>Any details if this is a special occasion:</b><br><textarea rows="5" cols="50" name="details">'.$event_details.'</textarea>';


  $EmailHandler .= '<p><input type="submit" name="sub" class="button" value="Submit">';
  $EmailHandler .= '</form>';
}

return $EmailHandler;


I've basiclly added some fields, changed the style of the email message and thats about it.

The main bug I've got is that if you submit a form without one of the required values, the fields that have the required valules shifts outside the actual text box, which is bad enough, but if you then fill in the missing field and re-submit all the values that where correct are now wrong as they are "outside" the text box for re-submittal.

This one has me really stumpted.

Edited by ikonia, 13 December 2007 - 10:06 AM.


#2 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 13 December 2007 - 11:43 AM

In a html form the form value is added at the value="$value" tag. The exception to this is the <textarea>$value</textarea>
You have also neglected to close several of your input fields (your name & email address).
try: www.w3schools.com

#3 ikonia

    Etomite Forum Fan

  • Member
  • Pip
  • 117 posts

Posted 13 December 2007 - 04:56 PM

View PostCris D., on Dec 13 2007, 11:43 AM, said:

In a html form the form value is added at the value="$value" tag. The exception to this is the <textarea>$value</textarea>
You have also neglected to close several of your input fields (your name & email address).
try: www.w3schools.com


thanks for responding. I'll close the missing tags now.

I don't understand your first comment, I understand even less how it relates to the problem I'm seeing.

thanks.

#4 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 13 December 2007 - 06:59 PM

Let me know if you can't get this resolved and I'll see if I can sneak a few minutes to have a look at the problem...

#5 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 13 December 2007 - 09:09 PM

Your code attempts to use 3 different methods for inserting values into the form fields.
1)[quote]$EmailHandler .= '<p>'.$telno_error.'<b>Contact Telephone Number:</b><br><input type="text" name="telno" >'.$telno.'</input>';[/quote] This one does not use the value='' and attempts to insert the value before the closing tag.

2)[quote]$EmailHandler .= '<p>'.$email_error.'<b>Your E-mail Address:</b><br><input type="text" name="email" class="text" value="'.$email.'">';[/quote] This one attempts to insert the value correctly but the closing tag is omitted.

3)[quote]$EmailHandler .= '<p><b>Any details if this is a special occasion:</b><br><textarea rows="5" cols="50" name="details">'.$event_details.'</textarea>';[/quote] This is correct method for <textarea> but not for the <text>.

It ir recommended practice to use self closing tags for text form fields <input type="text" name="field_name" value="what you want in the form field" [space] /> (self-closing tag) and this will be outside the text box even if you close the field with "</input>" .

All of this is explained at www.w3schools.com

Edited by Cris D., 13 December 2007 - 09:11 PM.


#6 ikonia

    Etomite Forum Fan

  • Member
  • Pip
  • 117 posts

Posted 18 December 2007 - 12:13 PM

View PostCris D., on Dec 13 2007, 09:09 PM, said:

Your code attempts to use 3 different methods for inserting values into the form fields.
1) This one does not use the value='' and attempts to insert the value before the closing tag.

2) This one attempts to insert the value correctly but the closing tag is omitted.

3) This is correct method for <textarea> but not for the <text>.

It ir recommended practice to use self closing tags for text form fields <input type="text" name="field_name" value="what you want in the form field""] /> (self-closing tag) and this will be outside the text box even if you close the field with "</input>" .

All of this is explained at www.w3schools.com


Big thank you for this, with your explination and a little reading I was able to fix this. Big thanks for your help on that, really appriciated, now have a better grasp, although not perfect of how the data handling works. I can only assume why the text was being shifted over to the right on submit was because of the tags not properly caused the script to not run properly and mess up the formatting, but I do have a slightly better grasp on how to handle the data now.

thanks for this, appriciated.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users