Autor
|
Tema: formulario dinamico (Leído 2,715 veces)
|
geshiro
Desconectado
Mensajes: 178
|
que le haria falta a mi funcion del ajax para que cuando se mande al dom no se vea como que si se duplicara la pagina? <?php include('../Models/product.php'); $product = new product(); session_start(); if (isset($_SESSION['login']) && $_SESSION['login']=='YES') {?> <!DOCTYPE html> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <link rel="stylesheet" href="../Resources/css/bootstrap.min.css"> <link rel="stylesheet" href="../Resources/css/main.css"> <!--Barra de Navegacion--> <nav class="navbar navbar-default frm-nav"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse"> <span class="sr-only">Cambiar Navegacion </span> <a href="#" class="navbar-brand">Sales </a> <ul class="nav navbar-nav navbar-right"> <a href="javascript:void(0)" onclick="" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-user"></span> <?php echo $_SESSION['name'];?><span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href="javascript:void(0)" onclick="settings();"><span class="glyphicon glyphicon-cog"></span> Settings </a></li> <li><a href="javascript:void(0)" onclick="edit();"><span class="glyphicon glyphicon-edit"></span> Edit </a></li> <li><a href="javascript:void(0)" onclick="change(); "><span class="glyphicon glyphicon-repeat"></span> Change your password </a></li> <li class="divider"></li> <li><a href="javascript:void(0)" onclick="cerrar();"><span class="glyphicon glyphicon-off"> Sign out </span></a></li> <ul class="nav navbar-nav navbar-right"> <a href="javascript:void(0)" onclick="" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-flag"></span> Reports <span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href=""><span class="glyphicon glyphicon-list"></span> Items </a></li> <li><a href="#"><span class="glyphicon glyphicon-list"></span> Parents list </a></li> <ul class="nav navbar-nav navbar-right"> <li><a href="javascript:void(0)" onclick=""><span class="glyphicon glyphicon-home"></span> home </a></li> <li><a href="javascript:void(0)" id="low_stock" onclick=""><span class="glyphicon glyphicon-alert"></span> slow stock <span id="notif" class="badge">0 </span></a></li> </nav> <ul class="nav nav-pills nav-stacked"> <li class="active"><a href="javascript:void(0)" onclick="home();"><span class="glyphicon glyphicon-home"></span> home </a></li> <li><a href="javascript:void(0)" onclick="product();"><span class=" glyphicon glyphicon-bed"></span> products </a></li> <li><a href="javascript:void(0)" onclick="sales();"><span class="glyphicon glyphicon-credit-card"></span> Sales </a></li> <li><a href="javascript:void(0)" id="msg" onclick="users();"><span class="glyphicon glyphicon-user"></span> Users <span id="notif" class="badge">0 </span></a></li> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModallabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel">Registro </h4> <form class="form-horizontal" id="formCliente"> <label for="fecha" class="control-label col-xs-5">date: </label> <input type="text" class="form-control" value="<?php echo date('y-m-d'); ?>" disabled="disabled"/> <label for="code" class="control-label col-xs-5">code: </label> <div class="col-xs-2 frm-code"> <input type="text" id="code" name="code" class="form-control" onkeyup="validacion('code');" aria-describedby="inputSuccess2Status"> <label for="product" class="control-label col-xs-5">Product: </label> <div class="col-xs-4 frm-product"> <select class="form-control" id="product" name="product" onchange="validacion('product');"> <label for="price" class="control-label col-xs-5">Price: </label> <div class="col-xs-3 frm-price"> <input type="text" class="form-control" id="price" name="price" onkeyup="validacion('price');"> <label for="stock" class="control-label col-xs-5">Stock: </label> <select class="form-control" id="stock" name="stock" onchange="validacion('stock')";> <div class="alert alert-success text-center" style="display:none;" id="success"> <div class="alert alert-danger text-center" style="display:none;" id="error"> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">close </button> <button type="button" class="btn btn-success" onclick="add_product();"><span class="glyphicon glyphicon-plus"></span> Add </button> <div class="tab-content nav col-md-8 frm-grid"> <div class="form-group col-xs-3 frm-search"> <div class="form-group has-feedback"> <input type="text" class="form-control" id="inputValidation" placeholder="Search"/> <span class="glyphicon glyphicon-search form-control-feedback"></span> <button class="btn btn-success frm-add" data-toggle="modal" data-target="#myModal"><span class="glyphicon glyphicon-plus"></span> Add products </button> <table class="table table-hover table-resposive"> <?php $product->show_product(); ?> function cerrar(){ $.ajax({ url:'../Controllers/user.php', type:'POST', data:"boton=cerrar" }).done(function(resp){ location.href = '../Views/' }); } function add_product(){ var code = $('#code').val(); var product = $('#product').val(); var price = $('#price').val(); var stock = $('#stock').val(); var valCheck = verificar(); if(valCheck == 1){ $.ajax({ url: '../Controllers/actions.php', type: 'POST', data: 'code='+code+'&product='+product+'&price='+price+'&stock='+stock+'&boton=add_product' }).done(function(ans){ if(ans == 'success'){ $('#code').val(""); $('#product').val('reset_product'); $('#price').val(""); $('#stock').val('rest_stock'); $('#success').show().delay(2000).fadeOut(); }else{ alert(ans); } }) } else { } } $(function(){ var message = $('#notif'); $('#msg').append(message); message.show('slow'); }); $(function(){ var message = $('#notif'); $('#low_stock').append(message); message.show('slow'); }); <?php } else { header("location: ./"); } ?>
<?php class product{ private $conexion; public function __construct(){ require_once('conexion.php'); $this->conexion = new conexion(); $this->conexion->conectar(); } function add($price,$stock,$code,$product){ $sql1 ="INSERT INTO product (price,stock,code,product) VALUES('$price','$stock','$code','$product')"; if($this->conexion->conexion->query($sql1)){ return true; } else{ return false; } $this->conexion->cerrar(); } function show_product(){ $sql = "SELECT * FROM product"; $record = $this->conexion->conexion->query($sql); $item =0; if(!$this->conexion->conexion->query($sql)){ printf("Errormessage: %s\n", $this->conexion->conexion->error); } if($record->num_rows>0){ while($show = $record->fetch_array(MYSQLI_ASSOC)){ $item += 1; echo '<tr> <td>'.$item.'</td> <td>'.$show["code"].'</td> <td>'.$show["product"].'</td> <td>'.$show["price"].'</td> <td>'.$show["stock"].'</td> <td><button class="btn btn-warning frm-del"><span class="glyphicon glyphicon-edit"><span<button><button class="btn btn-danger"><span class="glyphicon glyphicon-trash"><span<button></td> </tr>'; } } else{ echo '<tr><td colspan="5">no hay registros</td></tr>'; } } } ?>
|
|
« Última modificación: 26 Septiembre 2015, 06:33 am por geshiro »
|
En línea
|
|
|
|
0roch1
Desconectado
Mensajes: 123
|
Hola.
Perdón no entiendo tu pregunta, podrías replantearla.
Gracias.
|
|
|
En línea
|
|
|
|
geshiro
Desconectado
Mensajes: 178
|
osea que cuando registre mandarlo al dom pero al momento que lo mando me dubplica la pagina pero este es mi codigo $(document).ready(function(){ $('#add').click(function(){ $.ajax({ type: "POST", URL: "../Models/product.php", success: function(data){ $('#records').html(data); } }); }); });
|
|
|
En línea
|
|
|
|
Pablo Videla
|
Donde esta este elemento ? $('#records')
|
|
|
En línea
|
|
|
|
geshiro
Desconectado
Mensajes: 178
|
<?php include('../Models/product.php'); $product = new product(); session_start(); if (isset($_SESSION['login']) && $_SESSION['login']=='YES') {?> <!DOCTYPE html> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <link rel="stylesheet" href="../Resources/css/bootstrap.min.css"> <link rel="stylesheet" href="../Resources/css/main.css"> <!--Barra de Navegacion--> <nav class="navbar navbar-default frm-nav"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse"> <span class="sr-only">Cambiar Navegacion </span> <a href="#" class="navbar-brand">Sales </a> <ul class="nav navbar-nav navbar-right"> <a href="javascript:void(0)" onclick="" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-user"></span> <?php echo $_SESSION['name'];?><span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href="javascript:void(0)" onclick="settings();"><span class="glyphicon glyphicon-cog"></span> Settings </a></li> <li><a href="javascript:void(0)" onclick="edit();"><span class="glyphicon glyphicon-edit"></span> Edit </a></li> <li><a href="javascript:void(0)" onclick="change(); "><span class="glyphicon glyphicon-repeat"></span> Change your password </a></li> <li class="divider"></li> <li><a href="javascript:void(0)" onclick="cerrar();"><span class="glyphicon glyphicon-off"> Sign out </span></a></li> <ul class="nav navbar-nav navbar-right"> <a href="javascript:void(0)" onclick="" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-flag"></span> Reports <span class="caret"></span></a> <ul class="dropdown-menu" role="menu"> <li><a href=""><span class="glyphicon glyphicon-list"></span> Items </a></li> <li><a href="#"><span class="glyphicon glyphicon-list"></span> Parents list </a></li> <ul class="nav navbar-nav navbar-right"> <li><a href="javascript:void(0)" onclick=""><span class="glyphicon glyphicon-home"></span> home </a></li> <li><a href="javascript:void(0)" id="low_stock" onclick=""><span class="glyphicon glyphicon-alert"></span> slow stock <span id="notif" class="badge">0 </span></a></li> </nav> <ul class="nav nav-pills nav-stacked"> <li class="active"><a href="javascript:void(0)" onclick="home();"><span class="glyphicon glyphicon-home"></span> home </a></li> <li><a href="javascript:void(0)" onclick="product();"><span class=" glyphicon glyphicon-bed"></span> products </a></li> <li><a href="javascript:void(0)" onclick="sales();"><span class="glyphicon glyphicon-credit-card"></span> Sales </a></li> <li><a href="javascript:void(0)" id="msg" onclick="users();"><span class="glyphicon glyphicon-user"></span> Users <span id="notif" class="badge" onclick="push_up();">0 </span></a></li> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModallabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel">Registro </h4> <form class="form-horizontal" id="formCliente"> <label for="fecha" class="control-label col-xs-5">date: </label> <input type="text" class="form-control" value="<?php echo date('y-m-d'); ?>" disabled="disabled"/> <label for="code" class="control-label col-xs-5">code: </label> <div class="col-xs-2 frm-code"> <input type="text" id="code" name="code" class="form-control" onkeyup="validacion('code');" aria-describedby="inputSuccess2Status"> <label for="product" class="control-label col-xs-5">Product: </label> <div class="col-xs-4 frm-product"> <select class="form-control" id="product" name="product" onchange="validacion('product');"> <label for="price" class="control-label col-xs-5">Price: </label> <div class="col-xs-3 frm-price"> <input type="text" class="form-control" id="price" name="price" onkeyup="validacion('price');"> <label for="stock" class="control-label col-xs-5">Stock: </label> <select class="form-control" id="stock" name="stock" onchange="validacion('stock')";> <div class="alert alert-success text-center" style="display:none;" id="success"> <div class="alert alert-danger text-center" style="display:none;" id="error"> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">close </button> <button type="button" class="btn btn-success" onclick="add_product();" id="add"><span class="glyphicon glyphicon-plus"></span> Add </button> <div class="tab-content nav col-md-8 frm-grid"> <div class="form-group col-xs-3 frm-search"> <div class="form-group has-feedback"> <input type="text" class="form-control" id="inputValidation" placeholder="Search"/> <span class="glyphicon glyphicon-search form-control-feedback"></span> <button class="btn btn-success frm-add" data-toggle="modal" data-target="#myModal"><span class="glyphicon glyphicon-plus"></span> Add products </button> <table class="table table-hover table-resposive"> <?php $product->show_product(); ?> function cerrar(){ $.ajax({ url:'../Controllers/user.php', type:'POST', data:"boton=cerrar" }).done(function(resp){ location.href = '../Views/' }); } function add_product(){ var code = $('#code').val(); var product = $('#product').val(); var price = $('#price').val(); var stock = $('#stock').val(); var valCheck = verificar(); if(valCheck == 1){ $.ajax({ url: '../Controllers/actions.php', type: 'POST', data: 'code='+code+'&product='+product+'&price='+price+'&stock='+stock+'&boton=add_product' }).done(function(ans){ if(ans == 'success'){ $('#code').val(""); $('#product').val('reset_product'); $('#price').val(""); $('#stock').val('rest_stock'); $('#success').show().delay(2000).fadeOut(); }else{ alert(ans); } }) } else { } } $(document).ready(function(){ $('#add').click(function(){ $.ajax({ type: "POST", URL: "../Models/product.php", success: function(data){ $('#record').html(data); } }); }); }); $(function(){ var message = $('#notif'); $('#msg').append(message); message.show('slow'); }); $(function(){ var message = $('#notif'); $('#low_stock').append(message); message.show('slow'); }); <?php } else { header("location: ./"); } ?>
<?php class product{ private $conexion; public function __construct(){ require_once('conexion.php'); $this->conexion = new conexion(); $this->conexion->conectar(); } function add($price,$stock,$code,$product){ $sql1 ="INSERT INTO product (price,stock,code,product) VALUES('$price','$stock','$code','$product')"; if($this->conexion->conexion->query($sql1)){ return true; } else{ return false; } $this->conexion->cerrar(); } function show_product(){ $sql = "SELECT * FROM product"; $record = $this->conexion->conexion->query($sql); $item =0; if(!$this->conexion->conexion->query($sql)){ printf("Errormessage: %s\n", $this->conexion->conexion->error); } if($record->num_rows>0){ while($show = $record->fetch_array(MYSQLI_ASSOC)){ $item += 1; echo '<tr> <td>'.$item.'</td> <td>'.$show["code"].'</td> <td>'.$show["product"].'</td> <td>'.$show["price"].'</td> <td>'.$show["stock"].'</td> <td><button class="btn btn-warning frm-action"><span class="glyphicon glyphicon-edit"><span<button><button class="btn btn-danger frm-action"><span class="glyphicon glyphicon-trash"><span<button></td> </tr>'; } } else{ echo '<tr><td colspan="5">no hay registros</td></tr>'; } } } ?>
|
|
« Última modificación: 26 Septiembre 2015, 06:31 am por geshiro »
|
En línea
|
|
|
|
0roch1
Desconectado
Mensajes: 123
|
osea que cuando registre mandarlo al dom pero al momento que lo mando me dubplica la pagina pero este es mi codigo $(document).ready(function(){ $('#add').click(function(){ $.ajax({ type: "POST", URL: "../Models/product.php", success: function(data){ $('#records').html(data); } }); }); });
Qué es lo que duplica?, toda la tabla o los registros? En realidad eso no debería funcionar, solo debería mostrar la página en blanco porque es una clase. De esta función de la clase product deberías quitar la parte donde muestra los resultados y regresar únicamente los resultados para utilizarlos en una "vista" function show_product(){ $sql = "SELECT * FROM product"; $record = $this->conexion->conexion->query($sql); $item =0; if(!$this->conexion->conexion->query($sql)){ printf("Errormessage: %s\n", $this->conexion->conexion->error); } if($record->num_rows>0){ while($show = $record->fetch_array(MYSQLI_ASSOC)){ $item += 1; <td>'.$item.'</td> <td>'.$show["code"].'</td> <td>'.$show["product"].'</td> <td>'.$show["price"].'</td> <td>'.$show["stock"].'</td> <td><button class="btn btn-warning frm-action"><span class="glyphicon glyphicon-edit"><span<button><button class="btn btn-danger frm-action"><span class="glyphicon glyphicon-trash"><span<button></td> </tr>'; } } else{ echo '<tr><td colspan="5">no hay registros</td></tr>'; } }
|
|
|
En línea
|
|
|
|
geshiro
Desconectado
Mensajes: 178
|
ya pude hacer la vista pero cres que debe hacer la paginacion en otra clase y mandarla llamar?=
|
|
|
En línea
|
|
|
|
Pablo Videla
|
ya pude hacer la vista pero cres que debe hacer la paginacion en otra clase y mandarla llamar?=
Para tablas con paginación, buscador, etc usa datatables. https://www.datatables.net/
|
|
|
En línea
|
|
|
|
|
Mensajes similares |
|
Asunto |
Iniciado por |
Respuestas |
Vistas |
Último mensaje |
|
|
Formulario dinamico (php, mysql)
PHP
|
charly230
|
4
|
7,837
|
30 Noviembre 2006, 05:43 am
por charly230
|
|
|
Formulario Dinamico Simple (Si o No)
PHP
|
Conwafe
|
4
|
2,197
|
19 Febrero 2016, 12:16 pm
por engel lex
|
|
|
Formulario dinamico en php
Programación General
|
stR_ruBen
|
2
|
2,295
|
12 Febrero 2017, 00:33 am
por gato06
|
|
|
Ayuda necesito saber un formulario dinamico en PHP
Desarrollo Web
|
andregp095
|
2
|
2,519
|
4 Febrero 2017, 22:49 pm
por Razzari
|
|
|
Formulario Dinamico
PHP
|
shamaka
|
1
|
2,402
|
25 Abril 2018, 20:53 pm
por Penguin
|
|