Php and Jquery Validation: with Jquery Form Plugin

Posted by Jacinto on Stack Overflow See other posts from Stack Overflow or by Jacinto
Published on 2010-06-03T05:52:04Z Indexed on 2010/06/03 5:54 UTC
Read the original article Hit count: 287

Filed under:
|
|
|
|

Hi, This is the first time I have attempted to make a form using jquery and php. I used the folks over at Mid Mo Design as an example but even with that tutorial am still having trouble getting it to do what I want. This is the code I have been using. As well as jquery 1.4.1 and jQuery Form Plugin 2.43. Any help would be greatly appreciated.

css

scrollContact {

border-top: double 1px #0D0D0D; padding: 100px 50px 50px 50px; background: #020303; position: relative; overflow: hidden; width: 924px; text-align: justify; } .contactInfo { float:left; width: 214px; margin-right: 10px; margin-top: 5px; }

contactForm {

float: left; width: 700px; }

contactForm span {

float: left; margin:5px; width: 455px; }

input, textarea { -moz-border-radius:5px 5px 5px 5px; border:1px solid #001932; color:#BBBBBB; font:1.1em Verdana,Geneva,sans-serif; background: #0A0A0A; }

input:hover, textarea:hover { border:1px solid #0278f2; background: #242424; }

contactForm span input {

line-height:1.8em; width:430px; padding:11px 10px; margin: 0px 0px 10px 0px; }

contactForm input {

line-height:1.8em; width:200px; padding:11px 10px; margin: 5px; }

contactForm textarea {

height:190px; line-height:1.8em; width:430px; padding:10px; }

.message { background:#eee; color:#000; display:none; padding:10px; height: 70px; position: absolute; bottom:0px; }

Html

Contact Navigate To: Work services about contact Get A Free Quote
Thank you for your interest in contacting me. Please use the form to the right to contact me via email. I will respond to your inquiry as soon as possible. Please note all fields are required.
What Next?
Thank you for your interest in contacting me. Please use the form to the right to contact me via email. I will respond to your inquiry as soon as possible. Please note all fields are required. Your Message

Php

    <?php

$sendto = '[email protected]'; $subject = 'Contact from contact form'; $errormessage = 'Oops! There seems to have been a problem. May we suggest...'; $thanks = "Thanks for the email! We'll get back to you as soon as possible!"; $honeypot = "You filled in the honeypot! If you're human, try again!"; $emptyname = 'Entering your name?'; $emptyemail = 'Entering your email address?'; $emptytitle = 'Entering The Subject?'; $emptymessage = 'Entering a message?'; $alertname = 'Entering your name using only the standard alphabet?'; $alertemail = 'Entering your email in this format: [email protected]?'; $alerttitle = 'Entering the subject using only the standard alphabet?'; $alertmessage = "Making sure you aren't using any parenthesis or other escaping characters in the message? Most URLS are fine though!"; $alert = ''; $pass = 0;

function clean_var($variable) { $variable = strip_tags(stripslashes(trim(rtrim($variable)))); return $variable; }

if ( empty($_REQUEST['last']) ) {

if ( empty($_REQUEST['contactName']) ) { $pass = 1; $alert .= "

  • " . $emptyname . "
  • "; } elseif ( ereg( "[][{}()*+?.\^$|]", $_REQUEST['contactName'] ) ) { $pass = 1; $alert .= "
  • " . $alertname . "
  • "; } if ( empty($_REQUEST['contactEmail']) ) { $pass = 1; $alert .= "
  • " . $emptyemail . "
  • "; } elseif ( !eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)(.[a-z]{2,3})$", $_REQUEST['contactEmail']) ) { $pass = 1; $alert .= "
  • " . $alertemail . "
  • "; } if ( empty($_REQUEST['contactTitle']) ) { $pass = 1; $alert .= "
  • " . $emptytitle . "
  • "; } elseif ( ereg( "[][{}()*+?.\^$|]", $_REQUEST['contactTitle'] ) ) { $pass = 1; $alert .= "
  • " . $alerttitle . "
  • "; } if ( empty($_REQUEST['contactMessage']) ) { $pass = 1; $alert .= "
  • " . $emptymessage . "
  • "; } elseif ( ereg( "[][{}()*+?\^$|]", $_REQUEST['contactMessage'] ) ) { $pass = 1; $alert .= "
  • " . $alertmessage . "
  • "; }

    if ( $pass==1 ) {

    echo "$(\".message\").hide(\"slow\").show(\"slow\"); "; echo "" . $errormessage . ""; echo "

      "; echo $alert; echo "
    ";

    } elseif (isset($_REQUEST['message'])) {

      $message = "From: " . clean_var($_REQUEST['contactName']) . "\n";
    

    $message .= "Email: " . clean_var($_REQUEST['contactEmail']) . "\n"; $message .= "Telephone: " . clean_var($_REQUEST['contactTitle']) . "\n"; $message .= "Message: \n" . clean_var($_REQUEST['contactMessage']); $header = 'From:'. clean_var($_REQUEST['contactEmail']);

    mail($sendto, $subject, $message, $header);

    echo "$(\".message\").hide(\"slow\").show(\"slow\").animate({opacity: 1.0}, 4000).hide(\"slow\"); $(':input').clearForm() "; echo $thanks;

    die();

    }

    } else { echo "$(\".message\").hide(\"slow\").show(\"slow\"); "; echo $honeypot; } ?>

    © Stack Overflow or respective owner

    Related posts about php

    Related posts about JavaScript