Foros del Web » Programando para Internet » PHP »

[SOLUCIONADO] duda en poder insertar varios link url

Estas en el tema de duda en poder insertar varios link url en el foro de PHP en Foros del Web. hola es que tengo un formulario con registro tengo un campo de link url donde quiero poder hacer que si tengo barios url le de ...
  #1 (permalink)  
Antiguo 07/07/2015, 05:29
 
Fecha de Ingreso: junio-2012
Ubicación: En el Mundo
Mensajes: 759
Antigüedad: 11 años, 10 meses
Puntos: 10
duda en poder insertar varios link url

hola es que tengo un formulario con registro tengo un campo de link url donde quiero poder hacer que si tengo barios url le de a un bton y agrege otro campo para agregar otros url adicionales

como seria esto posible
  #2 (permalink)  
Antiguo 07/07/2015, 08:02
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: duda en poder insertar varios link url

Cita:
como seria esto posible
Con Javascript desde luego.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 07/07/2015, 08:53
 
Fecha de Ingreso: junio-2012
Ubicación: En el Mundo
Mensajes: 759
Antigüedad: 11 años, 10 meses
Puntos: 10
Respuesta: duda en poder insertar varios link url

y como podre recoger los $_POST

seria algo asi

<input name="cmd[0]" >
<input name="cmd[1]" >
<input name="cmd[2]" >
<input name="cmd[3]">
  #4 (permalink)  
Antiguo 07/07/2015, 09:00
Avatar de chronos682  
Fecha de Ingreso: febrero-2004
Ubicación: Tunja - Boyacá - Colombia
Mensajes: 627
Antigüedad: 20 años, 2 meses
Puntos: 69
Respuesta: duda en poder insertar varios link url

No habría necesidad de pasar los datos por POST, porque si estás escribiendo la url en un input text puedes usar getelementbyid o byname para traer el value del input text y añadir la nueva fila de la tabla con ese dato.
__________________
Si te gustó la respuesta dale +1

HERNÁN G. SIABATO M.
[email protected]
  #5 (permalink)  
Antiguo 07/07/2015, 09:17
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: duda en poder insertar varios link url

Cita:
Iniciado por xoceunder Ver Mensaje
y como podre recoger los $_POST

seria algo asi

<input name="cmd[0]" >
<input name="cmd[1]" >
<input name="cmd[2]" >
<input name="cmd[3]">
Fácil:
Código PHP:
Ver original
  1. var_dump($_POST['cmd']);

Recuerda que la notación de array ([]) producirá precisamente eso: un array de elementos.

Consulta el manual: http://www.php.net/variables.external
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #6 (permalink)  
Antiguo 07/07/2015, 09:55
 
Fecha de Ingreso: junio-2012
Ubicación: En el Mundo
Mensajes: 759
Antigüedad: 11 años, 10 meses
Puntos: 10
Respuesta: duda en poder insertar varios link url

ok y la forma de insertar a la mysql

INSERT INTO `links`(`id`, `ch_id`, `url`, `status`, `changed`) VALUES ([value-1],[value-2],[value-3],[value-4],[value-5])

como seria la forma de agregar con php
  #7 (permalink)  
Antiguo 07/07/2015, 10:07
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: duda en poder insertar varios link url

Pues tu lo has dicho:
Código PHP:
Ver original
  1. $sql = " INSERT INTO `links`(`id`, `ch_id`, `url`, `status`, `changed`) VALUES ([value-1],[value-2],[value-3],[value-4],[value-5])";

Donde [value-1] sería a {$_POST['cmd'][0]} y así sucesivamente.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #8 (permalink)  
Antiguo 07/07/2015, 10:08
Avatar de chronos682  
Fecha de Ingreso: febrero-2004
Ubicación: Tunja - Boyacá - Colombia
Mensajes: 627
Antigüedad: 20 años, 2 meses
Puntos: 69
Respuesta: duda en poder insertar varios link url

Ahora si no estoy entendiendo exactamente que es lo que quieres hacer. Yo pensé que lo que querías era agregar filas a una tabla con la url que escribieras en un input text al oprimir un botón, pero ahora veo que quieres agregarlas a una BD. Explica mejor qué es lo que quieres hacer para poder orientarte.
__________________
Si te gustó la respuesta dale +1

HERNÁN G. SIABATO M.
[email protected]
  #9 (permalink)  
Antiguo 07/07/2015, 10:16
 
Fecha de Ingreso: junio-2012
Ubicación: En el Mundo
Mensajes: 759
Antigüedad: 11 años, 10 meses
Puntos: 10
Respuesta: duda en poder insertar varios link url

ok chronos682

mira lo que quiero es hacer crear un

<input name="cmd[0]" type="text">

y si quiero agregar otro imput mas lo agrege con un boton como un ejemplo algo asi

http://prntscr.com/7pwfzw

y si le doy a add new link

apareca asi

http://prntscr.com/7pwgb8
  #10 (permalink)  
Antiguo 07/07/2015, 10:24
Avatar de chronos682  
Fecha de Ingreso: febrero-2004
Ubicación: Tunja - Boyacá - Colombia
Mensajes: 627
Antigüedad: 20 años, 2 meses
Puntos: 69
Respuesta: duda en poder insertar varios link url

Pero sólo necesitas que se duplique el input donde se escribe el link? O las check box de más abajo también.

Otra pregunta: al darle clic al botón de agregar nuevo link solamente se duplica el input? O se guarda en la bd el primero y se crea el nuevo input o al final de la página hay otro botón para hacer submit del formulario y almacenar a la vez todos los links agregados (que sería como yo lo haría).
__________________
Si te gustó la respuesta dale +1

HERNÁN G. SIABATO M.
[email protected]
  #11 (permalink)  
Antiguo 07/07/2015, 10:27
 
Fecha de Ingreso: junio-2012
Ubicación: En el Mundo
Mensajes: 759
Antigüedad: 11 años, 10 meses
Puntos: 10
Respuesta: duda en poder insertar varios link url

solo el input donde se escribe el link

y los link se guarda en bd en una tabla diferente

tabla contenido = striming
tabla link = ch_link

Última edición por xoceunder; 07/07/2015 a las 10:49
  #12 (permalink)  
Antiguo 07/07/2015, 11:09
 
Fecha de Ingreso: junio-2012
Ubicación: En el Mundo
Mensajes: 759
Antigüedad: 11 años, 10 meses
Puntos: 10
Respuesta: duda en poder insertar varios link url

ok encontre esto pero tengo problema

Código HTML:
Ver original
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2.                    "http://www.w3.org/TR/html4/loose.dtd">
  3.     <title></title>
  4.     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
  5.  
  6.     <script type="text/javascript">
  7.         $(document).ready(function() {
  8.             $('#btnAdd').click(function() {
  9.                 var num     = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
  10.                 var newNum  = new Number(num + 1);      // the numeric ID of the new input field being added
  11.  
  12.                 // create the new element via clone(), and manipulate it's ID using newNum value
  13.                 var newElem = $('#input' + num).clone().attr('id', 'input' + newNum);
  14.  
  15.                 // manipulate the name/id values of the input inside the new element
  16.                 newElem.children(':first').attr('id', 'name['+ newNum+']').attr('name', 'name['+ newNum+']');
  17.  
  18.                 // insert the new element after the last "duplicatable" input field
  19.                 $('#input' + num).after(newElem);
  20.  
  21.                 // enable the "remove" button
  22.                 $('#btnDel').attr('disabled','');
  23.  
  24.                 // business rule: you can only add 5 names
  25.                 if (newNum == 5)
  26.                     $('#btnAdd').attr('disabled','disabled');
  27.             });
  28.  
  29.             $('#btnDel').click(function() {
  30.                 var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
  31.                 $('#input' + num).remove();     // remove the last element
  32.  
  33.                 // enable the "add" button
  34.                 $('#btnAdd').attr('disabled','');
  35.  
  36.                 // if only one element remains, disable the "remove" button
  37.                 if (num-1 == 1)
  38.                     $('#btnDel').attr('disabled','disabled');
  39.             });
  40.  
  41.             $('#btnDel').attr('disabled','disabled');
  42.         });
  43.     </script>
  44. </head>
  45.  
  46.  
  47. <form id="myForm">
  48.     <div id="input1" style="margin-bottom:4px;" class="clonedInput">
  49.         Link: <input type="text" name="name[0]" id="name[0]" />
  50.     </div>
  51.  
  52.     <div>
  53.         <input type="button" id="btnAdd" value="add another name" />
  54.         <input type="button" id="btnDel" value="remove name" />
  55.     </div>
  56. </form>
  57.  
  58. </body>
  59. </html>

en que los campo me salen asi

<input name="cmd[0]" >
<input name="cmd[2]" >
<input name="cmd[3]" >
<input name="cmd[4]">
<input name="cmd[5]">

en vez que salgan asi

<input name="cmd[0]" >
<input name="cmd[1]" >
<input name="cmd[2]" >
<input name="cmd[3]">
<input name="cmd[4]">
  #13 (permalink)  
Antiguo 07/07/2015, 11:13
Avatar de chronos682  
Fecha de Ingreso: febrero-2004
Ubicación: Tunja - Boyacá - Colombia
Mensajes: 627
Antigüedad: 20 años, 2 meses
Puntos: 69
Respuesta: duda en poder insertar varios link url

Con este código es más fácil:

Código HTML:
Ver original
  1.     <head>
  2.         <title>Prueba</title>
  3.         <script>
  4.             function AddLink()
  5.             {
  6.                 var newdiv = document.createElement('div');
  7.                 newdiv.innerHTML = "Link: <input type='text' name='vinc[]'><br>";
  8.                 document.getElementById('vinculos').appendChild(newdiv);
  9.             }
  10.         </script>
  11.     </head>
  12.     <body>
  13.         <form>
  14.             <div id="vinculos">
  15.                 Link: <input type="text" name="vinc[]"><br>
  16.             </div>
  17.             <br><br>
  18.             <input type="button" value="Add link" onclick="AddLink();">
  19.         </form>
  20.     </body>
  21. </html>

Al final de la página creas un botón tipo submit y con POST recoges los valores de todos los campos vinc que se hayan creado.
__________________
Si te gustó la respuesta dale +1

HERNÁN G. SIABATO M.
[email protected]
  #14 (permalink)  
Antiguo 07/07/2015, 11:27
 
Fecha de Ingreso: junio-2012
Ubicación: En el Mundo
Mensajes: 759
Antigüedad: 11 años, 10 meses
Puntos: 10
Respuesta: duda en poder insertar varios link url

aver mira este amigo me gusta mas

Cita:
Iniciado por xoceunder Ver Mensaje
ok encontre esto pero tengo problema

Código HTML:
Ver original
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2.                    "http://www.w3.org/TR/html4/loose.dtd">
  3.     <title></title>
  4.     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
  5.  
  6.     <script type="text/javascript">
  7.         $(document).ready(function() {
  8.             $('#btnAdd').click(function() {
  9.                 var num     = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
  10.                 var newNum  = new Number(num + 1);      // the numeric ID of the new input field being added
  11.  
  12.                 // create the new element via clone(), and manipulate it's ID using newNum value
  13.                 var newElem = $('#input' + num).clone().attr('id', 'input' + newNum);
  14.  
  15.                 // manipulate the name/id values of the input inside the new element
  16.                 newElem.children(':first').attr('id', 'name['+ newNum+']').attr('name', 'name['+ newNum+']');
  17.  
  18.                 // insert the new element after the last "duplicatable" input field
  19.                 $('#input' + num).after(newElem);
  20.  
  21.                 // enable the "remove" button
  22.                 $('#btnDel').attr('disabled','');
  23.  
  24.                 // business rule: you can only add 5 names
  25.                 if (newNum == 5)
  26.                     $('#btnAdd').attr('disabled','disabled');
  27.             });
  28.  
  29.             $('#btnDel').click(function() {
  30.                 var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
  31.                 $('#input' + num).remove();     // remove the last element
  32.  
  33.                 // enable the "add" button
  34.                 $('#btnAdd').attr('disabled','');
  35.  
  36.                 // if only one element remains, disable the "remove" button
  37.                 if (num-1 == 1)
  38.                     $('#btnDel').attr('disabled','disabled');
  39.             });
  40.  
  41.             $('#btnDel').attr('disabled','disabled');
  42.         });
  43.     </script>
  44. </head>
  45.  
  46.  
  47. <form id="myForm">
  48.     <div id="input1" style="margin-bottom:4px;" class="clonedInput">
  49.         Link: <input type="text" name="name[0]" id="name[0]" />
  50.     </div>
  51.  
  52.     <div>
  53.         <input type="button" id="btnAdd" value="add another name" />
  54.         <input type="button" id="btnDel" value="remove name" />
  55.     </div>
  56. </form>
  57.  
  58. </body>
  59. </html>

en que los campo me salen asi

<input name="cmd[0]" >
<input name="cmd[2]" >
<input name="cmd[3]" >
<input name="cmd[4]">
<input name="cmd[5]">

en vez que salgan asi

<input name="cmd[0]" >
<input name="cmd[1]" >
<input name="cmd[2]" >
<input name="cmd[3]">
<input name="cmd[4]">
  #15 (permalink)  
Antiguo 07/07/2015, 11:36
Avatar de chronos682  
Fecha de Ingreso: febrero-2004
Ubicación: Tunja - Boyacá - Colombia
Mensajes: 627
Antigüedad: 20 años, 2 meses
Puntos: 69
Respuesta: duda en poder insertar varios link url

Ah bueno, si ese te funciona bien entonces dale por ese lado, es que a mí no me gusta enredarme tanto la vida con códigos largos, entre más simple sea y funcione para lo que lo necesito mejor.
__________________
Si te gustó la respuesta dale +1

HERNÁN G. SIABATO M.
[email protected]
  #16 (permalink)  
Antiguo 07/07/2015, 11:43
 
Fecha de Ingreso: junio-2012
Ubicación: En el Mundo
Mensajes: 759
Antigüedad: 11 años, 10 meses
Puntos: 10
Respuesta: duda en poder insertar varios link url

si si gracias ahora lo que quiero saber es como poder insertar esos link a la tabla
  #17 (permalink)  
Antiguo 07/07/2015, 11:49
Avatar de chronos682  
Fecha de Ingreso: febrero-2004
Ubicación: Tunja - Boyacá - Colombia
Mensajes: 627
Antigüedad: 20 años, 2 meses
Puntos: 69
Respuesta: duda en poder insertar varios link url

Por POST recoges los valores de los input:

Código PHP:
Ver original
  1. $myInputs = $_POST["cmd"];
  2. foreach ($myInputs as $eachInput) {
  3.      echo $eachInput . "<br>";
  4. }

Usas la variable $eachInput para ir agregando cada elemento a la BD con SQL.
__________________
Si te gustó la respuesta dale +1

HERNÁN G. SIABATO M.
[email protected]
  #18 (permalink)  
Antiguo 07/07/2015, 15:19
 
Fecha de Ingreso: junio-2012
Ubicación: En el Mundo
Mensajes: 759
Antigüedad: 11 años, 10 meses
Puntos: 10
Respuesta: duda en poder insertar varios link url

Cita:
Iniciado por chronos682 Ver Mensaje
Por POST recoges los valores de los input:

Código PHP:
Ver original
  1. $myInputs = $_POST["cmd"];
  2. foreach ($myInputs as $eachInput) {
  3.      echo $eachInput . "<br>";
  4. }

Usas la variable $eachInput para ir agregando cada elemento a la BD con SQL.
muchas gracias chronos682
  #19 (permalink)  
Antiguo 14/07/2015, 07:42
 
Fecha de Ingreso: junio-2012
Ubicación: En el Mundo
Mensajes: 759
Antigüedad: 11 años, 10 meses
Puntos: 10
Respuesta: duda en poder insertar varios link url

para insertar varios arrar

Código PHP:
Ver original
  1. foreach (array_combine($Url, $Title) as $url => $title) {
  2. echo $url .' '. $title;
  3. }

Etiquetas: formulario, link, poder, registro, url
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:08.