Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- forcing a specific mandatory text in text field


keneso - 5:03 pm on Sep 23, 2012 (gmt 0)


Hi,

I am trying to add another text field to an existing form with mandatory fields, this extra field should be filled in with a specific text, i.e I accept.
I know the other option would be the check-box (which I wouldn't know anyway), but I want the users to actually type "I accept the terms".

I have added these bits:

accept_terms: {// compound rule - my addition
required: true,
accept: true
},


accept: "<?php echo _ACCEPTTERMS_;?>", // my addition

to this script, but I don't know how to tell it to validate only the "I accept the terms" phrase.

<script type="text/javascript">
$(document).ready(function() {
$("#frmReg").validate({
rules: {
user_firstname: "required",// simple rule, converted to {required:true}
user_lastname: "required",
username: {
required: true,
minlength: 2
},
user_email: {// compound rule
required: true,
email: true
},

accept_terms: {// compound rule - my addition
required: true,
accept: true
},

},
messages: {
user_firstname: "<?php echo _FIRSTNAMEMANDATORY_;?>",
user_lastname: "<?php echo _LASTNAMEMANDATORY_;?>",
username: {
required: "<?php echo _USERNAMEMANDATORY_;?>",
minlength: "<?php echo _MINUSERNAMECHAR_;?>"
},
email: "<?php echo _EMAILVALID_;?>",
accept: "<?php echo _ACCEPTTERMS_;?>", // my addition
}
});
});
</script>


As a curiosity do you think this solution could work as a rudimental captcha?

Thank you


Thread source:: http://www.webmasterworld.com/javascript/4498859.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com