I have a form in CakePHP and I want to submit this form using JQuery. I'm looking for a solution on how to do this without using CakePHP's JsHelper, I want to use only the same JQuery native.
How to do this?
I'm trying to do this.
//add.ctp
<script type="text/javascript">
$(document).ready(function(){
$('#formulario').submit(function(){
var dados = $(this).serialize();
$.ajax({
type: "POST",
url: "UsersController.php",
data: dados,
success: function( data )
{
alert( data );
}
});
return false;
});
});
</script>
<div class="col-lg-6">
<?php echo $this->Form->create('User', array("id"=>"formulario"); ?>
<div class="form-group">
<?php echo $this->Form->input('nome', array( "label"=>"Nome",
"placeholder"=>"Informe o nome",
"class"=>"form-control",
));?>
</div>
<div class="form-group">
<?php echo $this->Form->input('email', array("label"=>"Email",
"placeholder"=>"Informe o email",
"class"=>"form-control",
));?>
</div>
<div class="form-group">
<?php echo $this->Form->input('senha', array("type"=>"password",
"maxlength"=>8,
"style"=>"width:200px;",
"class"=>"form-control"));?>
</div>
<button type="submit" class="btn btn-primary">Gravar</button>
<?php echo $this->Form->button("Limpar", array("type"=>"reset", "class"=>"btn btn-success"));?>
<?php echo $this->Form->end(); ?>
</div>