flori Posted December 13, 2012 Share Posted December 13, 2012 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 More sharing options...
satishpoul Posted December 13, 2012 Share Posted December 13, 2012 (edited) 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 December 13, 2012 by satishpoul Link to comment Share on other sites More sharing options...
flori Posted December 13, 2012 Author Share Posted December 13, 2012 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 Link to comment Share on other sites More sharing options...
satishpoul Posted December 13, 2012 Share Posted December 13, 2012 what exactly u want after filling details and after clicking download buttonand what exactly u want without filling details and clicking on download button. Link to comment Share on other sites More sharing options...
flori Posted December 13, 2012 Author Share Posted December 13, 2012 (edited) 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 December 13, 2012 by flori Link to comment Share on other sites More sharing options...
thescientist Posted December 13, 2012 Share Posted December 13, 2012 (edited) 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 enoughif(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 December 13, 2012 by thescientist Link to comment Share on other sites More sharing options...
satishpoul Posted December 13, 2012 Share Posted December 13, 2012 i think you required php_ajax just look at this example:http://www.w3schools.com/php/php_ajax_database.asp Link to comment Share on other sites More sharing options...
flori Posted December 14, 2012 Author Share Posted December 14, 2012 (edited) this is not enoughif(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 Why does not appear a link of download ? thank you very much for replying and i wait your solution for this problem Edited December 14, 2012 by flori Link to comment Share on other sites More sharing options...
flori Posted December 14, 2012 Author Share Posted December 14, 2012 i think you required php_ajax just look at this example: http://www.w3schools.com/php/php_ajax_database.asp Thank you very much but how can we solve this problem with PHP - AJAX and MySQLi wait your solution for this problem Link to comment Share on other sites More sharing options...
birbal Posted December 14, 2012 Share Posted December 14, 2012 you are missing type attribute in one of your script tag Link to comment Share on other sites More sharing options...
flori Posted December 14, 2012 Author Share Posted December 14, 2012 you are missing type attribute in one of your script tag Do you know what is? Link to comment Share on other sites More sharing options...
birbal Posted December 14, 2012 Share Posted December 14, 2012 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 More sharing options...
Ingolme Posted December 14, 2012 Share Posted December 14, 2012 you are missing type attribute in one of your script tagThe 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 More sharing options...
flori Posted December 14, 2012 Author Share Posted December 14, 2012 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 Thank you very much for your replying and i wait you solution for this problem Link to comment Share on other sites More sharing options...
thescientist Posted December 14, 2012 Share Posted December 14, 2012 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 More sharing options...
satishpoul Posted December 14, 2012 Share Posted December 14, 2012 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 More sharing options...
flori Posted December 15, 2012 Author Share Posted December 15, 2012 (edited) 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 December 15, 2012 by flori Link to comment Share on other sites More sharing options...
flori Posted December 15, 2012 Author Share Posted December 15, 2012 (edited) 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 December 15, 2012 by flori Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now