PHP Form not working at root level - JS Validation issue, maybe -
i totally stumped one. php form works fine when within folder on server see here http://getnice.co.uk/formtest/
but same code @ root level not work. yes pointing right places, not that. http://getnice.co.uk/form.html
below code.. think server issue? correct me if wrong.
<!-- contact start --> <section id="contact" class="pfblock pfblock-gray"> <div class="container"> <div class="row"> <div class="col-sm-8 col-sm-offset-2"> <div class="pfblock-header"> <h2 class="pfblock-title">contact us</h2> <div class="pfblock-line"></div> <div class="pfblock-subtitle"> tell business , needs are: </div> </div> </div> </div><!-- .row --> <div class="row"> <div class="col-sm-8 col-sm-offset-2"> <form id="contact-form" role="form" method="post" action="assets/php/contact.php"> <!-- <div class="contact.php"> --> <div class="form-group wow fadeinup"> <label class="sr-only" for="c_name">name</label> <input type="text" id="c_name" class="form-control" name="c_name" placeholder="name"> </div> <div class="form-group wow fadeinup" data-wow-delay=".1s"> <label class="sr-only" for="c_email">email</label> <input type="email" id="c_email" class="form-control" name="c_email" placeholder="e-mail"> </div> <div class="form-group wow fadeinup" data-wow-delay=".1s"> <label class="sr-only" for="c_design">design like</label> <select id="c_design" class="form-control" name="c_design" placeholder="name of design like"> <option value="" disabled selected>select design like</option> <option value="office">office based business</option> <option value="cafe or shop">cafe or shop</option> <option value="portfolio">portfolio style</option> <option value="other small">other small business</option> <option value="music">musician band style</option> <option value="agency">agency style</option> <option value="custom">custom design required</option> </select> </div> <div class="form-group wow fadeinup" data-wow-delay=".2s"> <textarea class="form-control" id="c_message" name="c_message" rows="7" placeholder="message"></textarea> </div> <button type="submit" class="btn btn-lg btn-block wow fadeinup" data-wow-delay=".3s">send message</button> </div> <div class="ajax-response"></div> </form> </div><!-- .row --> </div><!-- .container --> </section> <!-- contact end --> <!-- javascript files --> <script src="assets/js/jquery-1.11.1.min.js"></script> <script src="assets/bootstrap/js/bootstrap.min.js"></script> <script src="assets/js/jquery.parallax-1.1.3.js"></script> <script src="assets/js/imagesloaded.pkgd.js"></script> <script src="assets/js/jquery.sticky.js"></script> <script src="assets/js/smoothscroll.js"></script> <script src="assets/js/wow.min.js"></script> <script src="assets/js/waypoints.min.js"></script> <script src="assets/js/jquery.cbpqtrotator.js"></script> <script src="assets/js/custom.js"></script>
php
<?php if(isset($_post['c_message'])){ $name = $_post['c_name']; $email = $_post['c_email']; $vardropdown = $_post['c_design']; $message = $_post['c_message']; $to = 'me@gmail.com'; $subject = 'get nice contact form'; $mailcontent2="<html> <head> </head> <body> <table width='800' border='0' cellspacing='2' cellpadding='0'> <tr> <td align='left'> <p>hi,</p> <strong style='color:#c59800'>new request has been sent below details.</strong><br /><br /> <strong>name: </strong>".stripslashes($_request['c_name'])."<br /> <strong>email: </strong>".stripslashes($_request['c_email'])."<br /> <strong>design: </strong>".stripslashes($_request['c_design'])."<br /> <strong>message: </strong>".nl2br(stripslashes($_request['c_message']))."<br /><br /> <p>thanks</p> </td> </tr> </table> </body> </html> "; //echo $mailcontent2; $headers2 = "mime-version: 1.0" . "\r\n"; $headers2 .= "content-type: text/html; charset=iso-8859-1" . "\r\n"; $headers2 .= "from: ".$email." <".$email.">" . "\r\n"; $status = mail($to,$subject,$mailcontent2,$headers2); if($status == true){ $res['sendstatus'] = 'done'; //edit message here $res['message'] = 'thank mail has been sent'; } else{ $res['message'] = 'failed send mail. please email me @ hello@getnice.co.uk'; } echo json_encode($res);
}
js
/* ---------------------------------------------- /* * e-mail validation /* ---------------------------------------------- */ function isvalidemailaddress(emailaddress) { var pattern = new regexp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])*([a-z]|\d|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])))\.)+(([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])|(([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])([a-z]|\d|-|\.|_|~|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])*([a-z]|[\u00a0-\ud7ff\uf900-\ufdcf\ufdf0-\uffef])))\.?$/i); return pattern.test(emailaddress); }; /* ---------------------------------------------- /* * contact form ajax /* ---------------------------------------------- */ $('#contact-form').submit(function(e) { e.preventdefault(); var c_name = $('#c_name').val(); var c_email = $('#c_email').val(); var c_message = $('#c_message ').val(); var c_design = $('#c_design ').val(); var response = $('#contact-form .ajax-response'); var formdata = { 'c_name' : c_name, 'c_email' : c_email, 'c_design' : c_design, 'c_message' : c_message }; if (( c_name== '' || c_email == '' || c_message == '') || (!isvalidemailaddress(c_email) )) { response.fadein(500); response.html('<i class="fa fa-warning"></i> please fix errors , try again.'); } else { $.ajax({ type : 'post', // define type of http verb want use (post our form) url : 'assets/php/contact.php', // url want post data : formdata, // our data object datatype : 'json', // type of data expect server encode : true, success : function(res){ var ret = $.parsejson(json.stringify(res)); response.html(ret.message).fadein(500); } }); } return false; }); });
})(jquery);
move e.preventdefault();
towards end in custom.js
Comments
Post a Comment