I have the following form and this script to connect with the class operation.php it doesn't refresh and neither add the data into database.
I have no idea why it's not adding to the database
<form id="formulario" method="POST">
<textarea id="valor" name="valor"></textarea>
<input type="hidden" id="idproyecto" name="idproyecto" value="<?php echo $hist->idproyecto;?>"/>
<input type="hidden" id="idsprint" name="idsprint" value="<?php echo $hist->idsprint;?>"/>
<input type="hidden" id="idhistoria" name="idhistoria" value="<?php echo $hist->idhistoria;?>"/>
<input type="hidden" id="idusuario" name="idusuario" value="<?php echo $user->idusuario;?>"/>
<input id="Confirmar" class="button" name="operacion" type="submit" value="Confirmar" />
<span class="advertencia" style="display:none"> Please Enter Valid Data</span>
<span class="completado" style="display:none"> Registration Successfully</span>
</form>
$(function() {
$(".button").click(function() {
var idproyecto = $("#idproyecto").val();
var idsprint = $("#idsprint").val();
var idhistoria = $("#idhistoria").val();
var idusuario = $("#idusuario").val();
var valor = $("#valor").val();
var dataString = 'idproyecto='+ idproyecto + '&idsprint=' + idsprint + '&idhistoria=' + idhistoria + '&idusuario=' + idusuario + '&valor=' + valor;
alert(dataString);
if(valor=='')
{
$('.completado').fadeOut(200).hide();
$('.advertencia').fadeOut(200).show();
}else{
$.ajax({
type: "POST",
url: "../admin/poker/operacion_poker.php",
data: dataString,
success: function(){
$('.completado').fadeIn(200).show();
$('.advertencia').fadeOut(200).hide();}
});
}
return false;
});
});
And i have this class operation_poker.php to receive the values and add to database
include_once('../../clases/poker.php');
$operacion=$_REQUEST['operacion'];
$temporal_poker=new poker(0,$_REQUEST['idproyecto'],$_REQUEST['idsprint'],$_REQUEST['idhistoria'],$_REQUEST['idusuario'],$_REQUEST['valor'],0);
switch($operacion)
{
case 'Confirmar':
$temporal_poker->inserta_poker();
break;
}
Instead of using:
$(function() {
$(".button").click(function() {,
use this:
$(function() {
$("#formulario").submit(function(event) {
event.preventDefault();
Since your button is a submit type, you have to intercept form's submit
event for this to work correctly. Also note you have to prevent the normal submit behavior from occurring, so you also have to add the line event.preventDefault();
.
And Matthew is right, you should get your data from $_POST
, not $_REQUEST
.