Topic: Safe contact form using xajax & PHP (Read 2727 times)
Kill the googlebot
Gender:
Posts: 6
40 credits Members referred : 0
« on: Jun 01, 2007, 10:07:10 AM »
Hey people
I'm totally new to ajax/xajax, and not all that hot on php either... sorry 'bout that
I've had a long hard look at the tutorial to make the safe contact form (http://www.finalwebsites.com/tutorials/php_ajax_contact_form.php), but I can't work out where I need put all the different bits of code. The tute suggests to put the form and function 'before all the html code' - but if I put it in my page, anyone viewing the source will be able to see the passwords for the mail server.
Could someone please give me a clue here?
Many thanks
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6309
38674 credits Members referred : 374
It's time to use PHP5!
« Reply #1 on: Jun 01, 2007, 10:44:28 AM »
Hi,
are your sure that php is working well?
only output is parsed by the browser, can you post some code?
Kill the googlebot
Gender:
Posts: 6
40 credits Members referred : 0
« Reply #2 on: Jun 01, 2007, 11:06:28 AM »
Shortly after posting I realised I had to save my file as contact.php, not contact.html (duh), which has solved the issue of people viewing the source. However, there seems to be an issue with the following code:
At this point the browser tells me it happened across an unexpected T_STRING. I changed ('cform') to ("cform") which fixed that error, but now the form doesn't do anything...
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6309
38674 credits Members referred : 374
It's time to use PHP5!
« Reply #3 on: Jun 01, 2007, 11:17:47 AM »
you need to escape the single quotes (not replacing them with double quotes)
Kill the googlebot
Gender:
Posts: 6
40 credits Members referred : 0
« Reply #4 on: Jun 01, 2007, 01:28:53 PM »
Thanks very much, that's fixed it.. until it hits the next bug that is!
Now I get a popup message telling me that the XML Response received from the server is invalid - and it goes on to display the entire contents of my <html></html> tags.
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6309
38674 credits Members referred : 374
Thanks very much, that's fixed it.. until it hits the next bug that is!
Now I get a popup message telling me that the XML Response received from the server is invalid - and it goes on to display the entire contents of my <html></html> tags.
check the "php error" in this box and try to fix that
Kill the googlebot
Gender:
Posts: 6
40 credits Members referred : 0
« Reply #6 on: Jun 01, 2007, 03:41:21 PM »
Problem is that I can't see the entire message, because it's too long - it goes past the bottom of my screen and I can't move it up enough to see the end!
The email gets sent, but the form doesn't disappear.
I'm trying to fiddle with it a bit to see if I can hooky it back together, I think it's something to do with the following code:
Kill the googlebot
Gender:
Posts: 6
40 credits Members referred : 0
« Reply #8 on: Jun 01, 2007, 04:06:34 PM »
OK, I set debug=true, and the debug told me that the response was too long. So I seriously trimmed the HTML code to try and make it short enough to appear on the browser message, and it had advised me that it 'cannot modify header information' Headers already sent by my .php page, but a new header is requested by xajax.inc.php I'm guessing I can modify this somewhere?
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6309
38674 credits Members referred : 374
OK, I set debug=true, and the debug told me that the response was too long. So I seriously trimmed the HTML code to try and make it short enough to appear on the browser message, and it had advised me that it 'cannot modify header information' Headers already sent by my .php page, but a new header is requested by xajax.inc.php I'm guessing I can modify this somewhere?
there is a php error somewhere...undefined variable or something
you need to escape the single quotes (not replacing them with double quotes)
Seems i have same trouble. How to escape the single quotes? Can you write simple example? ... and ..hmm, is it javascript code? They asking to put this code before html and i have no glue why nothing working but now all is same.
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6309
38674 credits Members referred : 374
you need to escape the single quotes (not replacing them with double quotes)
Seems i have same trouble. How to escape the single quotes? Can you write simple example? ... and ..hmm, is it javascript code? They asking to put this code before html and i have no glue why nothing working but now all is same.
OMG!I am geek
Gender:
Posts: 57
370 credits Members referred : 0
« Reply #13 on: Aug 01, 2007, 12:53:50 PM »
This is easy, thank you.. i just think this working only in perl?
OMG!I am geek
Gender:
Posts: 57
370 credits Members referred : 0
« Reply #14 on: Aug 01, 2007, 01:21:25 PM »
one more question. I change this first peace of script from php to perl, i mean i just change <?php to <script type=.... etc. you see, in this tutorial at http://www.finalwebsites.com/tutorials/php_ajax_contact_form.php they dont explain which code is for js and which for php, so i just trying different ways. So, when i change to javascript, at least my page start work a bit.
Now i have next trouble. I've got fatal error with this line: <?php $xajax->printJavascript('xajax/'); ?> i read article at xajax tutorial and normaly this line is like that: "6. Between your tags, tell xajax to generate the necessary JavaScript: <?php $xajax->printJavascript(); ?>"
is this some link to xajax library? Why they use ('xajax/') instead of (). If this is link then i have to change some other things...
finaly .. i just thinking, maybe i have to just put simple mail form and forget about xajax..
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6309
38674 credits Members referred : 374
one more question. I change this first peace of script from php to perl, i mean i just change <?php to <script type=.... etc. you see, in this tutorial at http://www.finalwebsites.com/tutorials/php_ajax_contact_form.php they dont explain which code is for js and which for php, so i just trying different ways. So, when i change to javascript, at least my page start work a bit.
Now i have next trouble. I've got fatal error with this line: <?php $xajax->printJavascript('xajax/'); ?> i read article at xajax tutorial and normaly this line is like that: "6. Between your tags, tell xajax to generate the necessary JavaScript: <?php $xajax->printJavascript(); ?>"
is this some link to xajax library? Why they use ('xajax/') instead of (). If this is link then i have to change some other things...
finaly .. i just thinking, maybe i have to just put simple mail form and forget about xajax..
I guess this tutorial is not for php beginners (don't know why your try to translate php code to perl)
OMG!I am geek
Gender:
Posts: 57
370 credits Members referred : 0
« Reply #16 on: Aug 01, 2007, 02:13:52 PM »
yea, this really not for beginners. Just usually till this script was easy to use some php script or perl script into my pages. This is first where i cannot find solution.
i dont want to translate to perl, i just didnt now what php have same backward slash function. This is why. Anyway, i will try to find solution and if i will, i post here. I thought this mail form is very useful!
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6309
38674 credits Members referred : 374
yea, this really not for beginners. Just usually till this script was easy to use some php script or perl script into my pages. This is first where i cannot find solution.
i dont want to translate to perl, i just didnt now what php have same backward slash function. This is why. Anyway, i will try to find solution and if i will, i post here. I thought this mail form is very useful!
you don't need to learn so much about php to use this tutorial but you need to know some basics
function myFunction($get) { global $form, $error; $error = ''; $objResponse = new xajaxResponse(); $show_form = true; if (!empty($get['email']) && !empty($get['msg']) && !empty($get['name'])) { if (preg_match("/^[\w-]+(\.[\w-]+)*@([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})$/i", trim($get['email']))) { $email = preg_replace("/\r\n/", "", $get['email']); $from = preg_replace("/\r\n/", "", $get['name']); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = "smtp.yourserver.com"; $mail->SMTPAuth = true; $mail->Username = "postmaster@yourserver.com"; $mail->Password = "password"; $mail->From = "postmaster@yourserver.com"; $mail->FromName = "Webmaster"; $mail->AddAddress("admin@yourserver.com"); $mail->AddReplyTo($email, $from); $mail->Subject = "contact form using Xajax and phpmailer"; $mail->Body = $get['msg']; if ($mail->Send()) { $error = "The form is submitted and the mail is send."; $show_form = false; } else { $error = "There was a problem while sending the mail, please try again"; } } else { $error = "The entered e-mail address is not valid."; } } else { $error = "At least one of the fields is empty..."; } $data = (!$show_form) ? '<p class="contactMsg">'.$error.'</p>' : '<p class="contactMsg">'.$error.'</p>'.$form; $objResponse->addAssign('contact_result', 'innerHTML', $data); return $objResponse; }