jquery - How to display PHP if or else in customizable modal after form submit -



jquery - How to display PHP if or else in customizable modal after form submit -

i have working php contact form on 1 page site. when user clicks submit, taken separate php page displays if statement filled form correctly, or, page displays php else statement if filled out wrong. want instead of opening php page, rather user see modal may style fit site look/feel, displays if or else statements. these statements in php file:

function died($error) { // error code can go here echo "we sorry, there error(s) found form submitted. "; echo "these errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "please go , prepare these errors.<br /><br />"; die(); } // validate expected info exists if(!isset($_post['visitorname']) || !isset($_post['company_name']) || !isset($_post['email']) || !isset($_post['phone']) || !isset($_post['subject']) ||!isset($_post['comments'])) { died('we sorry, there appears problem form submitted.'); } $visitorname = $_post['visitorname']; // required $company_name = $_post['company_name']; // not required $email_from = $_post['email']; // required $phone = $_post['phone']; // not required $subject = $_post['subject']; // required $comments = $_post['comments']; // required $error_message = ""; $email_exp = '/^[a-za-z0-9._%-]+@[a-za-z0-9.-]+\.[a-za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'the email address entered not appear valid.<br />'; } $string_exp = "/^[a-za-z .'-]+$/"; if(!preg_match($string_exp,$visitorname)) { $error_message .= 'the name entered not appear valid.<br />'; } $string_exp = "/^[a-za-z .'-]+$/"; if(!preg_match($string_exp,$subject)) { $error_message .= 'the subject entered not appear valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'the message entered not appear valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); homecoming str_replace($bad,"",$string); } $email_message .= "name: ".clean_string($visitorname)."\n"; $email_message .= "company: ".clean_string($company_name)."\n"; $email_message .= "email: ".clean_string($email_from)."\n"; $email_message .= "phone: ".clean_string($phone)."\n"; $email_message .= "subject: ".clean_string($subject)."\n"; $email_message .= "message: ".clean_string($comments)."\n"; // section creates email headers $auth = array('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password); $headers = array('from' => $from_address, 'to' => $email_to, 'subject' => $email_subject, 'reply-to' => $reply_to); // section send email $smtp = mail::factory('smtp', $auth); $mail = $smtp->send($email_to, $headers, $email_message); if (pear::iserror($mail)) {?> <!-- include own failure message html here --> unfortunately, message not sent @ time. please seek 1 time again later. <!-- <?php echo("<p>". $mail->getmessage()."</p>"); ?> --> <?php } else { ?> give thanks contacting me. respond possible. <?php } } ?>

the next jquery/ajax close want because can submit form without leaving page, don't know how php if/else statements appear in alert box. don't appearance of alert box can't style it.

$ (function() { $('form.contactform').on('submit',function(){ var element=$(this), url=element.attr('action'), type=element.attr('method'), data={}; element.find('[name]').each(function(index,value){ var element=$(this), name=element.attr('name'); value=element.val(); data[name]=value; }); $.ajax({ url:url, type:type, data:data, success:function(response){ console.log(response); // add together give thanks pop here alert("need phone call php if/else here somehow."); } }); homecoming false; });

i want note not handy jquery/ajax/php. got sec bit of code user on here helped me. thanks.

you can create empty div anywhere on html page , have contents filled jquery when ajax phone call returns.

somewhere on page:

<div id="contactresponse"> </div>

then alter line contains alert phone call to:

$("#contactresponse").text(response.responsetext);

do happen utilize jquery ui? if do, turn div popup adding line:

$("#contactresponse").dialog();

php jquery html ajax forms

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -