Page 1 of 2

Help with feedback form

Posted: Mon Oct 02, 2006 12:02 pm
by keress
I'm getting an odd, incomplete message at the end of my feedback form. I'm wondering if someone can identify the cause. It follows hitting the "submit" button at the end of this form:

http://www.sisterbecky.com/acf/tour.htm

The php page is at:

http://www.sisterbecky.com/acf/tour-feedback.php

Thanks for any help.

Posted: Mon Oct 02, 2006 12:58 pm
by akimm
Since you're using a client side to bring a pop up, I assume javascript, and it does not relay the message, one of two errors is most likely the cause. Either your message that is meant to be sent is not actually in the right place or in the place period, or you may have made an error in writing the javascript.

What you should do is bring the code up, so we can see it, the php is really the one you need to place here, but thejavascript would make helping you a bit easier.

Posted: Mon Oct 02, 2006 1:02 pm
by akimm
This is what I see when I look at source

Code: Select all

<script language="JavaScript" type="text/JavaScript">
alert();
</script>
Your message was sent.  Thank you for contacting us, 
        we will be in touch shortly.
it should be something like this

Code: Select all

<script language="Javascript">
//this bit blocks the code from being processed for old browsers
<!--
// 
//as far as this alert is concerned, you need to actually have something in there..
alert ("This is a Javascript Alert")
//-->

</script>

Posted: Mon Oct 02, 2006 1:10 pm
by keress
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Here's the code.   This is a form I borrowed, I do understand the php fairly well, but I haven't any idea what the javascript is supposed to be doing, so it is quite likely there's an error there.

Code: Select all

<? 
 
 
echo '<script language="JavaScript" type="text/JavaScript">
alert('.$_POST[$varsd].');
</script>
';
$send_to = "linda@lkcwebdesign.com"; 
$recipient = "linda@lkcwebdesign.com";
$subject = "Aarons Creek Farm Tour Feedback";
$additional_headers = "From: linda@lkcwebdesign.com\r\n";
$additional_headers .="Content-type: text/html; charset=iso-8859-1\r\n";


$name = $_POST['name'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$fax = $_POST['fax'] ;
$attend = $_POST['attend'] ;
$number = $_POST['number'] ;
$lists = $_POST['lists'] ;
$availability = $_POST['availability'] ;
$email = $_POST['email'] ;
$emailaddress = $_POST['emailaddress'];
$fax = $_POST['fax'];
$faxnumber = $_POST['faxnumber'] ;
$mail = $_POST['mail'] ;
$name = $_POST['name'] ;
$street = $_POST['street'];
$city = $_POST['city'] ;
$state = $_POST['state'] ;
$zip = $_POST['zip'] ;
$phone = $_POST['phone'] ;
$comment = $_POST['comment'] ;
$http_referrer = getenv( "HTTP_REFERER" );



$email_body = 
'

<html>
<head>
<title>Aarons Creek Farms Tour &mdash; Attendance Feedback</title>

</head>

<body>
<table width="554" border="0" align="center" cellpadding="10" cellspacing="0">
   <tr>
    <td width="534" valign="top" bgcolor="#F4FFFF">	 <div align="center">
          <h1>Attendance Feedback </h1>    </div>    
        <p> Yes, we will attend lunch ['.$attend.']  </p>
		<p> Number attending: '.$number.' </p>
		<p>Send price list?  ['.$lists.'] 
		
		<p>   Send availability list?  ['.$availability.']  </p>
		<p>  Send by:  </p>
		<blockquote>
		  <p>  Email ['.$email.']	</p>
	      <blockquote>
	        <p>  Email address:  '.$emailaddress.' </p>
          </blockquote>
	      <p>Fax: ['.$fax.']</p>
	      <blockquote>
	        <p> Fax number:  '.$faxnumber.'  </p>
          </blockquote>
	      <p> Mail:  ['.$mail.']  </p>
	      <blockquote>
	        <p> Name:  '.$name.'  </p>
            <blockquote>
              <p> Street:  '.$street.'  </p>
              <p> City:  '.$city.'  </p>
              <p> State:  '.$state.'  </p>
              <p> Zip:  '.$zip.'  </p>
            </blockquote>
          </blockquote>
          <p> Phone:  '.$phone.' </p>
	  </blockquote>
	  <p> Comments:  '.$comment.'  </p>   

    </td>
  </tr>
</table>
</body>
</html>
';				


 if(mail($send_to,$subject,$email_body,$additional_headers))
 { 
     echo "Your message was sent.  Thank you for contacting us, 
        we will be in touch shortly.\n";} 
		else{      
		echo "Your message could not be sent.  Please call our office at the number below\n";
		}
			?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Oct 02, 2006 2:54 pm
by keress
Do I even need to use javascript here? What I really want to do is just refer the page over to a thank-you.htm page.

So . . . that code at the bottom using the curly brackets is going back to the javascript? I'm confused.

Thanks for the help.

Posted: Mon Oct 02, 2006 5:49 pm
by akimm
I don't think that the Javascript is nessesary at all, in order to refer to the thank_you.html you can look into using something along the lines of meta redirection, or maybe a code like this

Code: Select all

<?php
#if info is all validated and sent into you, then create an if statement 
if($validated) {
#code to redirect
header("location: http://www.yoursite.com/thank_you.html");
}
else {
header("location: http://www.yoursite.com/your_form.html"); 
?>
I would suggest you validate the info, use something like javascript. In fact d11wtq made an excellent class which will validate wonderfully, its in code snipplets, so check it out..

Posted: Mon Oct 02, 2006 5:50 pm
by akimm
The code at the very bottom, if the mail is sent just tells them, the person who sent it, that it was successful. Otherwise, it says that it failed and to call the office hours.

Posted: Mon Oct 02, 2006 8:32 pm
by keress
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Okay, I've been struggling with this all evening.  Thanks for bearing with me.  I've been trying to understand all the code this time around, but I've had enough of that for one go-round.  It's working and I'm not getting out of the boat again tonight.  Not sure why this version works, but oh well.  All I want to know now is how to change the last little bit so that it will refer to a 'thank-you.htm" page instead of going to a blank screen with plain text.

Code: Select all

<? 
 

$send_to = "linda@lkcwebdesign.com"; 
$recipient = "linda@lkcwebdesign.com";
$subject = "Aarons Creek Farm Tour Feedback";
$additional_headers = "From: linda@lkcwebdesign.com\r\n";
$additional_headers .="Content-type: text/html; charset=iso-8859-1\r\n";

$name = $_POST['name'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$fax = $_POST['fax'] ;
$attend = $_POST['attend'] ;
$number = $_POST['number'] ;
$lists = $_POST['lists'] ;
$availability = $_POST['availability'] ;
$email = $_POST['email'] ;
$emailaddress = $_POST['emailaddress'];
$fax = $_POST['fax'];
$faxnumber = $_POST['faxnumber'] ;
$mail = $_POST['mail'] ;
$name = $_POST['name'] ;
$street = $_POST['street'];
$city = $_POST['city'] ;
$state = $_POST['state'] ;
$zip = $_POST['zip'] ;
$phone = $_POST['phone'] ;
$comment = $_POST['comment'] ;
$http_referrer = getenv( "HTTP_REFERER" );



$email_body = 
'

<html>
<head>
<title>Aarons Creek Farms Tour &mdash; Attendance Feedback</title>

</head>

<body>
<table width="554" border="0" align="center" cellpadding="10" cellspacing="0">
   <tr>
    <td width="534" valign="top" bgcolor="#F4FFFF">	 <div align="center">
          <h1>Attendance Feedback </h1>    </div>    
        <p> Yes, we will attend lunch ['.$attend.']  </p>
		<p> Number attending: '.$number.' </p>
		<p>Send price list?  ['.$lists.'] 
		
		<p>   Send availability list?  ['.$availability.']  </p>
		<p>  Send by:  </p>
		<blockquote>
		  <p>  Email ['.$email.']	</p>
	      <blockquote>
	        <p>  Email address:  '.$emailaddress.' </p>
          </blockquote>
	      <p>Fax: ['.$fax.']</p>
	      <blockquote>
	        <p> Fax number:  '.$faxnumber.'  </p>
          </blockquote>
	      <p> Mail:  ['.$mail.']  </p>
	      <blockquote>
	        <p> Name:  '.$name.'  </p>
            <blockquote>
              <p> Street:  '.$street.'  </p>
              <p> City:  '.$city.'  </p>
              <p> State:  '.$state.'  </p>
              <p> Zip:  '.$zip.'  </p>
            </blockquote>
          </blockquote>
          <p> Phone:  '.$phone.' </p>
	  </blockquote>
	  <p> Comments:  '.$comment.'  </p>   

    </td>
  </tr>
</table>
</body>
</html>
';

 if(mail($send_to,$subject,$email_body,$additional_headers))
 { 
    echo "Your message was sent.  Thank you for contacting us, 
        we will be in touch shortly.\n";} 
		else{      
		echo "Your message could not be sent.  Please call our office at the number below\n";
		}
			?>
There's no validation I can see, but I can't really see what fields to require, given the nature of the form, and don't know how else to validate.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Oct 03, 2006 9:24 am
by SpecialK
Things like phone numbers and email should be validated to an extent. I've developed an mini CMS internally so I had to make sure that numbers and emails were valid because they would be going to a live site once they are entered.

You can use regular expressions to quickly do this.

As akimm already said
Instead of your echos
if(mail($send_to,$subject,$email_body,$additional_headers))
{
echo "Your message was sent. Thank you for contacting us,
we will be in touch shortly.\n";}
else{
echo "Your message could not be sent. Please call our office at the number below\n";
}

Code: Select all

if($validated && mail($send_to,$subject,$email_body,$additional_headers)){

   header("location: http://www.yoursite.com/thank_you.html"); 
}else{
   header("location: http://www.yoursite.com/your_form.html"); 
}

Posted: Sun Oct 08, 2006 10:31 am
by keress
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I got an error message when I tried to switch this code 
 
[quote]Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/sisterbecky.com/httpdocs/acf/tour-feedback.php:1) in /var/www/vhosts/sisterbecky.com/httpdocs/acf/tour-feedback.php on line 86[/quote]

I tried commenting out any reference to headers, but go the same message.  Here's he code:

Code: Select all

<? 
 

$send_to = "linda@lkcwebdesign.com"; 
$recipient = "linda@lkcwebdesign.com";
$subject = "Aarons Creek Farm Tour Feedback";
//$additional_headers = "From: linda@lkcwebdesign.com\r\n";
//$additional_headers .="Content-type: text/html; charset=iso-8859-1\r\n";

$name = $_POST['name'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$fax = $_POST['fax'] ;
$attend = $_POST['attend'] ;
$number = $_POST['number'] ;
$lists = $_POST['lists'] ;
$availability = $_POST['availability'] ;
$email = $_POST['email'] ;
$emailaddress = $_POST['emailaddress'];
$fax = $_POST['fax'];
$faxnumber = $_POST['faxnumber'] ;
$mail = $_POST['mail'] ;
$name = $_POST['name'] ;
$street = $_POST['street'];
$city = $_POST['city'] ;
$state = $_POST['state'] ;
$zip = $_POST['zip'] ;
$phone = $_POST['phone'] ;
$comment = $_POST['comment'] ;
$http_referrer = getenv( "HTTP_REFERER" );



$email_body = 
'

<html>
<head>
<title>Aarons Creek Farms Tour &mdash; Attendance Feedback</title>

</head>

<body>
<table width="554" border="0" align="center" cellpadding="10" cellspacing="0">
   <tr>
    <td width="534" valign="top" bgcolor="#F4FFFF">	 <div align="center">
          <h1>Attendance Feedback </h1>    </div>    
        <p> Yes, we will attend lunch ['.$attend.']  </p>
		<p> Number attending: '.$number.' </p>
		<p>Send price list?  ['.$lists.'] 
		
		<p>   Send availability list?  ['.$availability.']  </p>
		<p>  Send by:  </p>
		<blockquote>
		  <p>  Email ['.$email.']	</p>
	      <blockquote>
	        <p>  Email address:  '.$emailaddress.' </p>
          </blockquote>
	      <p>Fax: ['.$fax.']</p>
	      <blockquote>
	        <p> Fax number:  '.$faxnumber.'  </p>
          </blockquote>
	      <p> Mail:  ['.$mail.']  </p>
	      <blockquote>
	        <p> Name:  '.$name.'  </p>
            <blockquote>
              <p> Street:  '.$street.'  </p>
              <p> City:  '.$city.'  </p>
              <p> State:  '.$state.'  </p>
              <p> Zip:  '.$zip.'  </p>
            </blockquote>
          </blockquote>
          <p> Phone:  '.$phone.' </p>
	  </blockquote>
	  <p> Comments:  '.$comment.'  </p>   

    </td>
  </tr>
</table>
</body>
</html>
';

if(mail($send_to,$subject,$email_body)){ 

   header("location: http://www.sisterbecky.com/acf/thank-you.html"); 
}else{ 
   header("location: http://www.sisterbecky.com/acf/error-form.html"); 
}

// if(mail($send_to,$subject,$email_body,$additional_headers))
 //{ 
//    echo "Your message was sent.  Thank you for contacting us, 
 //       we will be in touch shortly.\n";} 
//		else{      
//		echo "Your message could not be sent.  Please call our office at the number below\n";
//		}
			?>
Also, the resulting email comes back as html code.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue Oct 10, 2006 10:34 am
by keress
Anybody have any clue why this code isn't doing what it's expected to do?

Posted: Tue Oct 10, 2006 10:44 am
by feyd

Posted: Tue Oct 10, 2006 11:06 am
by husky_42
keress wrote:feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I got an error message when I tried to switch this code 
 
[quote]Warning: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/sisterbecky.com/httpdocs/acf/tour-feedback.php:1) in /var/www/vhosts/sisterbecky.com/httpdocs/acf/tour-feedback.php on line 86[/quote]

I tried commenting out any reference to headers, but go the same message.  Here's he code:

Code: Select all

<? 
 

$send_to = "linda@lkcwebdesign.com"; 
$recipient = "linda@lkcwebdesign.com";
$subject = "Aarons Creek Farm Tour Feedback";
//$additional_headers = "From: linda@lkcwebdesign.com\r\n";
//$additional_headers .="Content-type: text/html; charset=iso-8859-1\r\n";

$name = $_POST['name'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;
$fax = $_POST['fax'] ;
$attend = $_POST['attend'] ;
$number = $_POST['number'] ;
$lists = $_POST['lists'] ;
$availability = $_POST['availability'] ;
$email = $_POST['email'] ;
$emailaddress = $_POST['emailaddress'];
$fax = $_POST['fax'];
$faxnumber = $_POST['faxnumber'] ;
$mail = $_POST['mail'] ;
$name = $_POST['name'] ;
$street = $_POST['street'];
$city = $_POST['city'] ;
$state = $_POST['state'] ;
$zip = $_POST['zip'] ;
$phone = $_POST['phone'] ;
$comment = $_POST['comment'] ;
$http_referrer = getenv( "HTTP_REFERER" );



$email_body = 
'

<html>
<head>
<title>Aarons Creek Farms Tour &mdash; Attendance Feedback</title>

</head>

<body>
<table width="554" border="0" align="center" cellpadding="10" cellspacing="0">
   <tr>
    <td width="534" valign="top" bgcolor="#F4FFFF">	 <div align="center">
          <h1>Attendance Feedback </h1>    </div>    
        <p> Yes, we will attend lunch ['.$attend.']  </p>
		<p> Number attending: '.$number.' </p>
		<p>Send price list?  ['.$lists.'] 
		
		<p>   Send availability list?  ['.$availability.']  </p>
		<p>  Send by:  </p>
		<blockquote>
		  <p>  Email ['.$email.']	</p>
	      <blockquote>
	        <p>  Email address:  '.$emailaddress.' </p>
          </blockquote>
	      <p>Fax: ['.$fax.']</p>
	      <blockquote>
	        <p> Fax number:  '.$faxnumber.'  </p>
          </blockquote>
	      <p> Mail:  ['.$mail.']  </p>
	      <blockquote>
	        <p> Name:  '.$name.'  </p>
            <blockquote>
              <p> Street:  '.$street.'  </p>
              <p> City:  '.$city.'  </p>
              <p> State:  '.$state.'  </p>
              <p> Zip:  '.$zip.'  </p>
            </blockquote>
          </blockquote>
          <p> Phone:  '.$phone.' </p>
	  </blockquote>
	  <p> Comments:  '.$comment.'  </p>   

    </td>
  </tr>
</table>
</body>
</html>
';

if(mail($send_to,$subject,$email_body)){ 

   header("location: http://www.sisterbecky.com/acf/thank-you.html"); 
}else{ 
   header("location: http://www.sisterbecky.com/acf/error-form.html"); 
}

// if(mail($send_to,$subject,$email_body,$additional_headers))
 //{ 
//    echo "Your message was sent.  Thank you for contacting us, 
 //       we will be in touch shortly.\n";} 
//		else{      
//		echo "Your message could not be sent.  Please call our office at the number below\n";
//		}
			?>
Also, the resulting email comes back as html code.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color][/quote]

When you use header, it doesn't like any character sent to the browser.  Nor does it like if your <?php is not the absolute first character of your page.  Even 1 space before it, will generate that type of error.

Side note, must web server will have no problem with <? but some will have issues with it.  It is not a must, but a general preference to use the <?php ?> tags when programming with PHP.  It is not a must, be some server could give you some issues with it.

Posted: Tue Oct 10, 2006 11:11 am
by feyd
husky_42 wrote:Side note, must web server will have no problem with <? but some will have issues with it. It is not a must, but a general preference to use the <?php ?> tags when programming with PHP. It is not a must, be some server could give you some issues with it.
Short tag support has been removed in future versions of PHP. It will be a must sooner rather than later. :)

hello

Posted: Tue Oct 10, 2006 6:47 pm
by akimm
something you must understand before implementing this code, the way you send this mail is very insecure, and quite easily hacked.

I recommend swiftmailer.

however if you still want the help just reply back and i'll help you the best I can.