I have a simple html form for the user confirmation. Once the user registers they are sent a link to this page with a GET variable attached like this: http://mysite/confirm?code=xyz123
I am using the jquery validation plugin for all my form validations.
I have this validation code:
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$('#confirm').validate(
{rules: {
code: {
required: true,
minlength: 32,
maxlength: 32
}
},
messages: {
code: {
required: "Please enter the confirmation code",
minlength: "Confirmation code is {0} characters",
maxlength: "Confirmation code is {0} characters"
}
},
submitHandler: function(form){
$.get("confirmnewuser.php",
$('#code').val,
function(data){
if(data.status == 0){
$('#message').append("<span class='error'>Error: " + data.message + "</span>");
}
else{
$('.container').hide();
$('.short_explanation').hide();
$('#message').append("<span>" + data.message + "</span>");
}
},
"json");
}
});
});
</script>
I would like to test if the GET['code'] variable is set which can be done easily like this:
var $_GET = <?php echo json_encode($_GET); ?>;
But at this point I don’t know where to add this to my existing validation code and I don’t know how to call the form submit handler (I’m fairly new to jquery/javascript).
Alternatively if the GET variable is not set then the page should load normally and the user can then enter their code in the input box.
Edit: added Form Code
<form id='confirm' method='get' accept-charset='UTF-8'>
<div class='short_explanation'>* required fields</div>
<div id='message'></div>
<div class='container'>
<label for='code' >Confirmation Code:* </label><br/>
<input type='text' name='code' id='code' maxlength="32" /><br/>
</div>
<div class='container'>
<input type='submit' name='submit' id="submit" value='Confirm' />
</div>
</form>
As I understand the situation is,
if user comes with this url->
http://mysite/confirmThe page will load normally, and user will enter its own code, then click the submit button.
But if user comes with this url->
http://mysite/confirm?code=xyz123Form will load with defualt code “xyz12”, and submit automatically.
If this is right than here is my solution,