<script src="jquery-validate/lib/jquery.js" type="text/javascript"></script>
<script src="jquery-validate/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery.validator.addMethod("steam_id", function(value, element) {
return this.optional(element) || /^STEAM_0:(0|1):[0-9]{1}[0-9]{0,8}$/.test(value);});
jQuery.validator.addMethod("nome",function(value,element){
return this.optional(element) || /^[a-zA-Z0-9._ -]{4,16}$/.test(value);});
$(document).ready(function(){
var validator = $("#form3").bind("invalid-form.validate", function() {
$("#summary").html("O formulário contém " + validator.numberOfInvalids() + " erros.");
}).validate({
debug: false,
errorElement: "em",
errorContainer: $("#warning, #summary"),
errorPlacement: function(error, element) {
error.appendTo( element.parent("td").next("td") );
},
success: function(label) {
label.text("").addClass("success");
if(!validator.numberOfInvalids()){
$("#form3").submit(function() {
var username = $('#username').attr('value');
var nickname = $('#nickname').attr('value');
var steamid = $('#steamid').attr('value');
$.ajax({
type: "POST",
url: "ajax.php",
data: "username="+ username +"& nickname="+ nickname +"& steamid="+ steamid,
success: function(){
$('#form3').hide(function(){$('div.success').fadeIn();});
}
});
return false;
});
}
},
rules: {
steamid: {
required: true,
steam_id : true
},
username: {
required: true,
nome: true
},
nickname: {
required: true,
nome: true
}
}
});
});
</script>
Hi there, I'm almost theree to finish this script. the only thing I can't do is being able to submit this form when the field are already completed.
It has to label them ok first and I wanted for example, my registered users whern they go to this page some have their field completed with information from my database and if they click submit nothing happens, I have to click on one filed to label it ok and then when I click submit it works.. But what I wanted is this to work if the fields are already written, the client just clicks the submit button to insert his data.
I don't know if you understood me but maybe if you see my form you understand:
<form class="cmxform" id="form3" method="POST">
<h2 id="summary"></h2>
<fieldset>
<legend>Adicionar VIP</legend>
<table>
<tr>
<td><label for="username">Nome</label></td>
<td><input id="username" name="username"
title="Mínimo de 4 caracteres" value="<?php echo "$row->name"; ?>" />
</td>
<td></td>
</tr>
<tr>
<td><label for="steamid">Steam Id* </label></td>
<td><input id="steamid" name="steamid" title="Steam Id inválida!" value="<?php echo "$row->steamid"; ?>" /></td>
<td></td>
</tr>
<tr>
<td><label for="nickname">Nickname</label></td>
<td><input name="nickname" id="nickname" title="Mínimo de 4 caracteres" value="<?php echo "$row->userid"; ?>" /></td>
<td></td>
</tr>
<tr>
<td>Validade:</td>
<td align="center">60 Dias</td>
</tr>
<tr><td></td>
<td><input align="middle" class="submit" type="submit" value="Adicionar"/></td>
</tr>
</table>
</fieldset>
</form>
Thanks