Topic: I'm about ready to commit suicide - please prevent!

Here is my test page. http://tinyurl.com/yg9nw9a Press submit and you can see how it performs.

I have tried about a million things. I am simply trying to combine jquery validation plugin with ajax form submit. I have resigned myself to being happy with a simple javascript popup thank you message via an ajax submit. This is done in order to prevent the user from leaving the page on form submit.

I "think" I need to use a submitHandler in the validation JS and call the ajax submit. But I am unable to piece it together. This is the very last piece of the puzzle for me and this site. Once I get this backend stuff working it's all formatting (easy stuff). 

The JS validation works perfect. When JS is off I'll just use my good old PHP script I have. Here is the page in it's entirety. Please help put me out of my misery. I'm definitely working above my pay-grade here.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>edit-your-website.com</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="css/styles.css" rel="stylesheet" type="text/css">
<style type="text/css">
html, body {
overflow:hidden;
background:none;
}
#contactform {
float:left;
position:relative;
width:319px;
padding:0;
font-size:13px;
}
#contactform:hover, #contactform:focus {
background-position:0 -322px;
}
#contactform input {
margin:4px 0 15px;
border:0;
padding:13px;
height:17px; /* actual height = 43px */
width:293px; /* actual width = 244px */
background:url(img/input3.jpg) 100% 0 no-repeat;
}
* html #contactform input {
background-attachment:fixed;
}
#contactform input:hover, #contactform input:focus {
background-position:100% -43px;
outline:0;
}
#contactform textarea {
height:129px; /* actual height = 155px */
width:293px; /* actula width = 319px */
border:0;
background:none;
background:url(img/textarea.jpg) 0 0 no-repeat;
overflow:auto;
outline:0;
padding:13px;
resize:none;
}
#contactform textarea:hover, #contactform textarea:focus {
background-position:0 -155px;
}
#contactform input#captcha {
width:108px;
margin:13px 0 0; /* if JS is off this kicks in */
float:left;
background:url(img/captcha.jpg) 0 0 no-repeat;
}
#contactform input#captcha:hover {
background-position:0 -43px;
}
#contactform input#contact-login {
float:right;
width:134px;
height:43px;
cursor:pointer;
margin:13px 0 0;
background:url(img/captcha.jpg) no-repeat;
}
* html #contactform input#contact-login {
margin-left:-6px;
}
#contactform #contact-login:hover, #contactform #contact-login:focus {
background-position:0 -43px;
}
#contactform input.error {background-position:100% -86px;}
#contactform textarea.error {background-position:0 -310px;}
#contactform input#captcha.error {background-position:0 -86px;}
.required {color:red; font-weight:bold;}
</style>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/validate.js"></script>
<script type="text/javascript">
    $.validator.methods.equal = function(value, element, param) {
        return value == param;
    };
    $(document).ready(function(){
        $("#contactform").validate({
                rules: {
                    name: "required",
                    email: {
                    required: true,
                    email: true
                    },
                    comments: {
                    required: true,
                    minlength: 5
                    },
                    captcha: {
                        equal: 4
                    }
                },
                messages: {
                    email: "",
                    name: "",
                    comments: "",
                    captcha: ""
                }
            });
    });
</script>
<script type="text/javascript">
function clearText(a){if(a.defaultValue==a.value){a.value=""}else{if(a.value==""){a.value=a.defaultValue}}};
</script>

</head>
<body>

<form id="contactform" method="post" action="http://www.edit-your-website.com/formmail.php">
    <div>
        <input type="text" id="name" name="name">
       
        <input type="text" id="email" name="email">

        <textarea id="comments" name="comments" rows="3" cols="35"></textarea>

        <input type="text" id="captcha" name="captcha" value="2 + 2 = ?" onFocus="clearText(this)" onBlur="clearText(this)">
        <input type="submit" id="contact-login" value="">
   </div>
</form>

</body>
</html>

Last edited by Eric (November 1, 2009 11:31 am)

Vote up Vote down

Re: I'm about ready to commit suicide - please prevent!

Sorry can't help.  Tear your hair out and rip your clothes if you must, but please don't commit suicide no web site is worth that sacrifice...!!!

Vote up Vote down

Re: I'm about ready to commit suicide - please prevent!

virtual wrote:

Sorry can't help.  Tear your hair out and rip your clothes if you must, but please don't commit suicide no web site is worth that sacrifice...!!!

I guess I was being a little over dramatic. This is just driving me crazy! Usually (actually always) if I read and apply myself for this long Im able to put the pieces together. Although, with this, I just keep running into brick walls. Here is my simplified post of where I'm at now, and what I'm trying to accomplish. http://www.sitepoint.com/forums/showthread.php?t=645199 I'll try for a couple more days, and if I still can't do it I will just give up and do it the only way I know how (the less cool way).

You see, the problem I'm having is, there are a few good tuts around the web that show how to do an Ajax submit and fade out the form and replaceing it with a thank you message. But none of them provide any validation along with it. Well other than empty or not. And I do not posess the ability to add validation to it. I can't combine the two.

Last edited by Eric (November 2, 2009 12:23 pm)

Vote up Vote down

Re: I'm about ready to commit suicide - please prevent!

I did it!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

JQuery validation + Ajax Submit + full PHP validation = the best!

Vote up Vote down

Re: I'm about ready to commit suicide - please prevent!

Good for you. How long for the hair to grow back? Keep us posted... big_smile

My signature goes here --> X

Vote up Vote down

Re: I'm about ready to commit suicide - please prevent!

and I just figured out how to fade the form out and replace it with a thank you message. I couldn't figure out all the JS ways to do it, so I somehow managed it with css (well a lttle js). When I'm all done with my nightmare site I will put it all in plain English. That is, if I can remember how I did it by that time.

The only thing left is to figure out how to write an addMethod for the validation rules. I need to prevent url's from being input into the textarea. I posted all the details here if anyone has a clue... http://stackoverflow.com/questions/1668 … ion-plugin

Last edited by Eric (November 3, 2009 5:02 pm)

Vote up Vote down