Jump to content

If statement doesn't work?


flori

Recommended Posts

I've created some if / else statements to get a download when a user hit click jf he fields name and email but doesn"t work for my site http://my-easy-woodw...ng-projects.com because it is do download without field name and email contact.php is

<?php$field_name = $_POST['cf_name'];$field_email = $_POST['cf_email'];$field_message = $_POST['cf_message'];$mail_to = 'dedalusonline@yahoo.com';$subject = 'Message from a site visitor '.$field_name;$body_message = 'From: '.$field_name."\n";$body_message .= 'E-mail: '.$field_email."\n";$body_message .= 'Message: '.$field_message;$headers = 'From: '.$field_email."\r\n";$headers .= 'Reply-To: '.$field_email."\r\n";$mail_status = mail($mail_to, $subject, $body_message, $headers);if ($mail_status) {	echo "<script>\n";	echo 'var str = \"download\"' . "\n";	echo "document.write(str.link(\"http://www.myshedplans.com/12BY8SHED.pdf\"));\n";	echo "</script>\n";}else {	echo  "<script language=\"javascript\" type=\"text/javascript\">";	echo  "alert('Message failed. Please, send an email to gordon@template-help.com');";	echo  "window.location = 'contact_page.html';";	echo "</script>";}?>

Link to comment
Share on other sites

try this=><?phpif(isset($_POST['cf_name'],$_POST['cf_email'],$_POST['cf_message'])){$field_name = $_POST['cf_name'];$field_email = $_POST['cf_email'];$field_message = $_POST['cf_message']; $mail_to = 'dedalusonline@yahoo.com';$subject = 'Message from a site visitor '.$field_name;$body_message = 'From: '.$field_name."\n";$body_message .= 'E-mail: '.$field_email."\n";$body_message .= 'Message: '.$field_message;$headers = 'From: '.$field_email."\r\n";$headers .= 'Reply-To: '.$field_email."\r\n";$mail_status = mail($mail_to, $subject, $body_message, $headers);if ($mail_status) { echo "<script>\n"; echo 'var str = \"download\"' . "\n"; echo "document.write(str.link(\"http://www.myshedplans.com/12BY8SHED.pdf\"));\n"; echo "</script>\n";}}else{ echo "<script language=\"javascript\" type=\"text/javascript\">"; echo "alert('Message failed. Please, send an email to gordon@template-help.com');"; echo "window.location = 'contact_page.html';"; echo "</script>";}?>

Edited by satishpoul
Link to comment
Share on other sites

try this=><?phpif(isset($_POST['cf_name'],$_POST['cf_email'],$_POST['cf_message'])){$field_name = $_POST['cf_name'];$field_email = $_POST['cf_email'];$field_message = $_POST['cf_message']; $mail_to = 'dedalusonline@yahoo.com';$subject = 'Message from a site visitor '.$field_name;$body_message = 'From: '.$field_name."\n";$body_message .= 'E-mail: '.$field_email."\n";$body_message .= 'Message: '.$field_message;$headers = 'From: '.$field_email."\r\n";$headers .= 'Reply-To: '.$field_email."\r\n";$mail_status = mail($mail_to, $subject, $body_message, $headers);if ($mail_status) { echo "<script>\n"; echo 'var str = \"download\"' . "\n"; echo "document.write(str.link(\"http://www.myshedplans.com/12BY8SHED.pdf\"));\n"; echo "</script>\n";}}else{ echo "<script language=\"javascript\" type=\"text/javascript\">"; echo "alert('Message failed. Please, send an email to gordon@template-help.com');"; echo "window.location = 'contact_page.html';"; echo "</script>";}?>
doesn't work alsoyou can hit direct download your free plan now ,and show a white window without nothinglike this page1cl.pngpage2j.png
Link to comment
Share on other sites

what exactly u want after filling details and after clicking download buttonand what exactly u want without filling details and clicking on download button.
when visitor site filling detailes and hitdownload your free plan now i want shows link of download and when he hit link of download shows a link of installwhen visitor site dont fill all detailes i want shows alert Message failed. Please, send an email to gordon@template-help.com thats all thank you very much for your help and replying and i wait your solution for this problem Edited by flori
Link to comment
Share on other sites

try this=><?phpif(isset($_POST['cf_name'],$_POST['cf_email'],$_POST['cf_message'])){$field_name = $_POST['cf_name'];$field_email = $_POST['cf_email'];$field_message = $_POST['cf_message']; $mail_to = 'dedalusonline@yahoo.com';$subject = 'Message from a site visitor '.$field_name;$body_message = 'From: '.$field_name."\n";$body_message .= 'E-mail: '.$field_email."\n";$body_message .= 'Message: '.$field_message;$headers = 'From: '.$field_email."\r\n";$headers .= 'Reply-To: '.$field_email."\r\n";$mail_status = mail($mail_to, $subject, $body_message, $headers);if ($mail_status) { echo "<script>\n"; echo 'var str = \"download\"' . "\n"; echo "document.write(str.link(\"http://www.myshedplans.com/12BY8SHED.pdf\"));\n"; echo "</script>\n";}}else{ echo "<script language=\"javascript\" type=\"text/javascript\">"; echo "alert('Message failed. Please, send an email to gordon@template-help.com');"; echo "window.location = 'contact_page.html';"; echo "</script>";}?>
this is not enough
if(isset($_POST['cf_name'],$_POST['cf_email'],$_POST['cf_message']))

by virtue of the form being submitted, even with empty values, they will all be isset. i.e. "" will pass the isset check. At the very minimum the OP would want to use !empty(XXX) for each POST param, since an empty("") will return true. Probably what would be even better is if the OP validated the clients information client side to prevent the user from submitting an empty form. In the event the JS is turned off, have a failsafe on the server side as well. i.e.

<?phpif(!empty($_POST['cf_name']) && !empty($_POST['cf_email']) && !empty($_POST['cf_message'])){  $field_name = $_POST['cf_name'];  $field_email = $_POST['cf_email'];  $field_message = $_POST['cf_message'];  $mail_to = 'dedalusonline@yahoo.com';  $subject = 'Message from a site visitor '.$field_name;  $body_message = 'From: '.$field_name."\n";  $body_message .= 'E-mail: '.$field_email."\n";  $body_message .= 'Message: '.$field_message;  $headers = 'From: '.$field_email."\r\n";  $headers .= 'Reply-To: '.$field_email."\r\n";  $mail_status = mail($mail_to, $subject, $body_message, $headers);  if ($mail_status) {	echo "<script>\n";	echo 'var str = \"download\"' . "\n";	echo "document.write(str.link(\"http://www.myshedplans.com/12BY8SHED.pdf\"));\n";	echo "</script>\n";  }else {	echo  "<script language=\"javascript\" type=\"text/javascript\">";	echo  "alert('Message failed. Please, send an email to gordon@template-help.com');";	echo  "window.location = 'contact_page.html';";	echo "</script>";  }}else{  echo  "<script language=\"javascript\" type=\"text/javascript\">";   echo  "alert('Please fill out the entire form');";  echo  "window.location = 'contact_page.html';";  echo "</script>";};?>

Edited by thescientist
Link to comment
Share on other sites

this is not enough
if(isset($_POST['cf_name'],$_POST['cf_email'],$_POST['cf_message']))

by virtue of the form being submitted, even with empty values, they will all be isset. i.e. "" will pass the isset check. At the very minimum the OP would want to use !empty(XXX) for each POST param, since an empty("") will return true. Probably what would be even better is if the OP validated the clients information client side to prevent the user from submitting an empty form. In the event the JS is turned off, have a failsafe on the server side as well. i.e.

<?phpif(!empty($_POST['cf_name']) && !empty($_POST['cf_email']) && !empty($_POST['cf_message'])){  $field_name = $_POST['cf_name'];  $field_email = $_POST['cf_email'];  $field_message = $_POST['cf_message'];  $mail_to = 'dedalusonline@yahoo.com';  $subject = 'Message from a site visitor '.$field_name;  $body_message = 'From: '.$field_name."\n";  $body_message .= 'E-mail: '.$field_email."\n";  $body_message .= 'Message: '.$field_message;  $headers = 'From: '.$field_email."\r\n";  $headers .= 'Reply-To: '.$field_email."\r\n";  $mail_status = mail($mail_to, $subject, $body_message, $headers);  if ($mail_status) {	echo "<script>\n";	echo 'var str = \"download\"' . "\n";	echo "document.write(str.link(\"http://www.myshedplans.com/12BY8SHED.pdf\"));\n";	echo "</script>\n";  }else {	echo  "<script language=\"javascript\" type=\"text/javascript\">";	echo  "alert('Message failed. Please, send an email to gordon@template-help.com');";	echo  "window.location = 'contact_page.html';";	echo "</script>";  }}else{  echo  "<script language=\"javascript\" type=\"text/javascript\">";   echo  "alert('Please fill out the entire form');";  echo  "window.location = 'contact_page.html';";  echo "</script>";};?>

There is an error in your solution because when you fill alldetails and after clicking download button Nothing happens ,a white window without a link of downloadthis is what happen page3h.pngjnaan.gifjnaan.gifjnaan.gifjnaan.gifjnaan.gifjnaan.gifjnaan.gifpage2w.pngWhy does not appear a link of download ? thank you very much for replying and i wait your solution for this problem Edited by flori
Link to comment
Share on other sites

you are missing type attribute in one of your script tag

Link to comment
Share on other sites

echo "<script>\n";        echo 'var str = \"download\"' . "\n";        echo "document.write(str.link(\"http://www.myshedplans.com/12BY8SHED.pdf\"));\n";        echo "</script>\n";

will be

echo "<script type='text/javascript>\n";        echo 'var str = \"download\"' . "\n";        echo "document.write(str.link(\"http://www.myshedplans.com/12BY8SHED.pdf\"));\n";        echo "</script>\n";

Link to comment
Share on other sites

you are missing type attribute in one of your script tag
The type attribute is not required in HTML 5 as it's assumed that Javascript is the only scripting language.
Link to comment
Share on other sites

echo "<script>\n";		echo 'var str = \"download\"' . "\n";		echo "document.write(str.link(\"http://www.myshedplans.com/12BY8SHED.pdf\"));\n";		echo "</script>\n";

will be

echo "<script type='text/javascript>\n";		echo 'var str = \"download\"' . "\n";		echo "document.write(str.link(\"http://www.myshedplans.com/12BY8SHED.pdf\"));\n";		echo "</script>\n";

The same thing ,also not working and this video explains what happen gUZNq.gifThank you very much for your replying and i wait you solution for this problem
Link to comment
Share on other sites

There is an error in your solution because when you fill alldetails and after clicking download button Nothing happens ,a white window without a link of downloadthis is what happen
try checking for errors in your PHP code.
 error_reporting(E_ALL);ini_set('display_errors', '1');

add some echo statements, anything. Try chipping away it piece by piece. I only wrote this code off the top of my head. It should only be something small to fix, but it is important to be able to know what the problem is first.

Link to comment
Share on other sites

when u submit or click on download js function just like in following examplehttp://www.w3schools.com/php/php_ajax_database.aspand put the validation and alert message whatever u want to set.and if all goes well thensend the data for mailing function in php just like in example from above link ===>> xmlhttp.open("GET","mail.php?q="+str,true);(q as a paramete to send mail) and then in mail.php u can do whatever u want to do.or give him link instead of table in above example.

Link to comment
Share on other sites

try checking for errors in your PHP code.
 error_reporting(E_ALL); ini_set('display_errors', '1'); 

add some echo statements, anything. Try chipping away it piece by piece. I only wrote this code off the top of my head. It should only be something small to fix, but it is important to be able to know what the problem is first.

I tried, but to no avail Thank you very much sirfor your replying and i wait your solution for this problem Edited by flori
Link to comment
Share on other sites

when u submit or click on download js function just like in following example http://www.w3schools...ax_database.asp and put the validation and alert message whatever u want to set. and if all goes well then send the data for mailing function in php just like in example from above link ===>> xmlhttp.open("GET","mail.php?q="+str,true);(q as a paramete to send mail) and then in mail.php u can do whatever u want to do. or give him link instead of table in above example.
I tried, but to no avail Thank you very much sirfor your replying and i wait your solution for this problem Edited by flori
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...