php contact form with jquery style -
this first post - very new this. have contact form opens jquery pressing button. when submit form using php, box closes again can see 'view form' button. when click on box/form opens again , although form submitted - box stay open display 'thank submitting etc' message - appreciated. thanks. here jquery , php:
(function() { $('html').addclass('js'); var contactform = { container: $('#contact'), config: { effect: 'slidetoggle', speed: 500 }, init: function(config) { $.extend(this.config, config); $('<button></button>', { text: 'view form' }) .insertafter( '.show-form' ) .on( 'click', this.show ); }, show: function() { var cf = contactform, container = cf.container, config = cf.config; if ( container.is(':hidden') ) { contactform.close.call(container); container[config.effect](config.speed); } }, close: function() { var $this = $(this), // #contact config = contactform.config; if ( $this.find('span.close').length ) return; $('<span class=close>x</span>') .prependto(this) .on('click', function() { // = span $this[config.effect](config.speed); }) } }; contactform.init({ // effect: 'fadetoggle', speed: 300 }); })(); <form> <?php function spamcheck($field) { //filter_var() sanitizes e-mail //address using filter_sanitize_email $field=filter_var($field, filter_sanitize_email); //filter_var() validates e-mail //address using filter_validate_email if(filter_var($field, filter_validate_email)) { return true; } else { return false; } } if (isset($_request['email'])) {//if "email" filled out, proceed //check if email address invalid $mailcheck = spamcheck($_request['email']); if ($mailcheck==false) { echo "error - please check details"; } else {//send email $email = $_request['email'] ; $subject = $_request['subject'] ; $message = $_request['message'] ; mail("myemail@hotmail.co.uk", "subject: $subject", $message, "from: $email" ); echo "thank query."; } } else {//if "email" not filled out, display form echo "<form method='post' action='thanks.php'> email: <input name='email' type='text' /><br /><br /> subject: <input name='subject' type='text' /><br /><br /> message:<br /> <textarea name='message' rows='5' cols='40'> </textarea><br /> <input type='submit' /> </form>"; } ?>
Comments
Post a Comment