Hi,
Some user told me about a code bug in the contact form tutorial. In Internet explorer the form fields become empty if the form was submitted and not send because of some missing fields. The example below is changed to fix that. The following code is also updated to use the NEW xajax version (so the old version I used the tutorial will not work).
<?php require_once('xajax/xajax_core/xajax.inc.php'); require_once('PHPMailer/class.phpmailer.php'); function myFunction($get) { $error = ''; $data = ''; $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..."; } if (!$show_form) $objResponse->assign('contact_result', 'innerHTML', ''); $objResponse->assign('contactMsg', 'innerHTML', $error); return $objResponse; } $xajax = new xajax(); //$xajax->configure('debug',true); $xajax->register(XAJAX_FUNCTION, 'myFunction'); $xajax->processRequest(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"> <head> <title>Ajax example</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <?php $xajax->printJavascript('/xajax/'); ?> <style type="text/css" media="screen"> <!-- label { width: 130px; padding-right:10px; display:block; float:left; } --> </style> </head> <body> <h2>AJAX Mail DEMO</h2> <div id="contact_result"> <form id="cform"> <div> <label for="name">Name</label> <input name="name" type="text" id="naam" value="" size="25" /> </div> <div> <label for="email">E-mail</label> <input name="email" type="text" id="email" value="" size="25" /> </div> <div> <label for="msg">Message</label> <textarea name="msg" id="msg" cols="45" rows="5"></textarea> </div> <div style="padding-top:5px;"> <label for="subbtn"></label> <input type="button" id="subbtn" value="Submit" onclick="xajax_myFunction(xajax.getFormValues('cform'));" /> </div> </form> <p id="contactMsg"></p> </div> </body> </html>