Foros del Web » Programando para Internet » PHP »

Creacion de div con valores de post

Estas en el tema de Creacion de div con valores de post en el foro de PHP en Foros del Web. Hola, estoy intentando crear un div luego de pedir datos por metodo post en un formulario pero no me funciona. Sé que no esta optimizado ...
  #1 (permalink)  
Antiguo 21/05/2011, 16:36
 
Fecha de Ingreso: mayo-2011
Mensajes: 23
Antigüedad: 12 años, 10 meses
Puntos: 0
Creacion de div con valores de post

Hola, estoy intentando crear un div luego de pedir datos por metodo post en un formulario pero no me funciona. Sé que no esta optimizado el codigo pero no soy un experto. Espero algun consejo o metodo para que funcione. Desde ya muchas gracias Saludos.

<?php if($_SERVER['REQUEST_METHOD']=="GET"){ ?>
<form method="POST">
Top
<input type="text" name="top" />
<br />
Left
<input type="text" name="left" />
<br />
Width
<input type="text" name="width" />
<br />
Height
<input type="text" name="height" />
<br />
<input type="submit"/>
</form>
<?php
}else if($_SERVER['REQUEST_METHOD']=="POST"){
if(isset($_POST["top"])){
if(is_numeric($_POST["top"]))
$top= $_POST["top"];
else {
echo 'Top no es numerico';
}
}
if(isset($_POST["left"])){
if(is_numeric($_POST["left"]))
$left= $_POST["left"];
else {
echo 'Left no es numerico';
}
}
if(isset($_POST["width"])){
if(is_numeric($_POST["width"]))
$width= $_POST["width"];
else {
echo 'Width no es numerico';
}
}
if(isset($_POST["height"])){
if(is_numeric($_POST["height"]))
$height= $_POST["height"];
else {
echo 'Width no es numerico';
}
}
if(is_numeric($width)&&($height)&&($left)&&($top)) {
echo "<div top=$top.'px' left=$left.'px' height=$height.'px' width=$width.'px' backgroud-color=blue>";
echo "</div>";
}
}
?>
  #2 (permalink)  
Antiguo 21/05/2011, 16:43
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: Creacion de div con valores de post

Creo el HTML que generas es invalido, ¿no deberían de estar las variables de top, left, height y width dentro de el atributo de style?

Saludos.
  #3 (permalink)  
Antiguo 21/05/2011, 17:00
 
Fecha de Ingreso: mayo-2011
Mensajes: 23
Antigüedad: 12 años, 10 meses
Puntos: 0
Respuesta: Creacion de div con valores de post

Es cierto gracias, ahi lo modifique pero me sigue sin aparecer el Div. Espero una respuesta gracias

<?php if($_SERVER['REQUEST_METHOD']=="GET"){ ?>
<form method="POST">
Top
<input type="text" name="top" />
<br />
Left
<input type="text" name="left" />
<br />
Width
<input type="text" name="width" />
<br />
Height
<input type="text" name="height" />
<br />
<input type="submit"/>
</form>
<?php
}else if($_SERVER['REQUEST_METHOD']=="POST"){
if(isset($_POST["top"])){
if(is_numeric($_POST["top"]))
$top= $_POST["top"];
else {
echo 'Top no es numerico';
}
}
if(isset($_POST["left"])){
if(is_numeric($_POST["left"]))
$left= $_POST["left"];
else {
echo 'Left no es numerico';
}
}
if(isset($_POST["width"])){
if(is_numeric($_POST["width"]))
$width= $_POST["width"];
else {
echo 'Width no es numerico';
}
}
if(isset($_POST["height"])){
if(is_numeric($_POST["height"]))
$height= $_POST["height"];
else {
echo 'Width no es numerico';
}
}
if(is_numeric($width)&&($height)&&($left)&&($top)) {
echo "<div style = top:$top.'px'; left:$left.'px'; height:$height.'px'; width:$width.'px'; backgroud-color:blue>";
echo "</div>";
}
}
?>
  #4 (permalink)  
Antiguo 21/05/2011, 17:03
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: Creacion de div con valores de post

Creo que tienes problemas con las comillas, verifica este tema:

http://www.forosdelweb.com/f18/como-...1/#post2414268
  #5 (permalink)  
Antiguo 21/05/2011, 17:38
 
Fecha de Ingreso: mayo-2011
Mensajes: 23
Antigüedad: 12 años, 10 meses
Puntos: 0
Respuesta: Creacion de div con valores de post

Gracias por link. Probe sacando las concatenaciones del div pero no me funciona. No se si el problema esta ahi o hay algun codigo erroneo de PHP propiamente dicho, porque la verdad estoy haciendo mis primeros ejercicios en este tipo de codigo.
  #6 (permalink)  
Antiguo 21/05/2011, 21:04
Avatar de gildus  
Fecha de Ingreso: agosto-2003
Mensajes: 1.495
Antigüedad: 20 años, 8 meses
Puntos: 105
Respuesta: Creacion de div con valores de post

Holas,

Le di una vista rapida al codigo, y mas o menos seria asi:

Código PHP:
Ver original
  1. <?php
  2. if(isset($_GET))
  3. { ?>
  4.     <form method="POST">
  5.         Top
  6.         <input type="text" name="top" />
  7.         <br />
  8.         Left
  9.         <input type="text" name="left" />
  10.         <br />
  11.         Width
  12.         <input type="text" name="width" />
  13.         <br />
  14.         Height
  15.         <input type="text" name="height" />
  16.         <br />
  17.         <input type="submit"/>
  18.     </form>
  19. <?php
  20. }
  21. else
  22. {   if(isset($_POST))
  23.     {
  24.         if(isset($_POST["top"]))
  25.         {
  26.             if(is_numeric($_POST["top"]))       $top= $_POST["top"];
  27.             else            echo 'Top no es numerico';
  28.         }
  29.        
  30.         if(isset($_POST["left"]))
  31.         {   if(is_numeric($_POST["left"]))      $left= $_POST["left"];
  32.             else            echo 'Left no es numerico';
  33.         }
  34.        
  35.         if(isset($_POST["width"]))
  36.         {
  37.             if(is_numeric($_POST["width"]))     $width= $_POST["width"];
  38.             else            echo 'Width no es numerico';
  39.            
  40.         }
  41.    
  42.         if(isset($_POST["height"]))
  43.         {
  44.             if(is_numeric($_POST["height"]))    $height= $_POST["height"];
  45.             else            echo 'Width no es numerico';
  46.         }
  47.    
  48.         if(is_numeric($width)&& is_numeric($height) && is_numeric($left) && is_numeric($top))
  49.         {
  50.             echo "<div style = 'top:".$top."px; left:".$left."px; height:".$height."px; width:".$width."px; backgroud-color:blue;'>";
  51.             echo "</div>";
  52.         }
  53.     }
  54. }
  55. ?>

Saludos
Gildus
__________________
.: Gildus :.
  #7 (permalink)  
Antiguo 22/05/2011, 12:26
 
Fecha de Ingreso: mayo-2011
Mensajes: 23
Antigüedad: 12 años, 10 meses
Puntos: 0
Respuesta: Creacion de div con valores de post

Gracias gildus por la mano, estuve haciendo algunas modificaciones y ahora el programa no me tira error al enviarlo por post pero no me dibuja el div. Creo q el problema esta en el echo de los divs pero probe varias formas y nunca aparece. Agradezco los aportes.

<?php if($_SERVER['REQUEST_METHOD']=="GET"){ ?>
<form method="POST">
Top
<input type="text" name="top" />
<br />
Left
<input type="text" name="left" />
<br />
Width
<input type="text" name="width" />
<br />
Height
<input type="text" name="height" />
<br />
<input type="submit"/>
</form>
<?php
}else if($_SERVER['REQUEST_METHOD']=="POST"){
if(isset($_POST["top"])){
if(is_numeric($_POST["top"]))
$top= $_POST["top"];
else {
echo 'Top no es numerico';
}
}
if(isset($_POST["left"])){
if(is_numeric($_POST["left"]))
$left= $_POST["left"];
else {
echo 'Left no es numerico';
}
}
if(isset($_POST["width"])){
if(is_numeric($_POST["width"]))
$width= $_POST["width"];
else {
echo 'Width no es numerico';
}
}
if(isset($_POST["height"])){
if(is_numeric($_POST["height"]))
$height= $_POST["height"];
else {
echo 'Height no es numerico';
}
}
if(is_numeric($_POST["top"])&& is_numeric($_POST["left"])&& is_numeric($_POST["height"])&& is_numeric($_POST["width"])){
echo "<div style = 'top:".$_POST["top"]."px; left:".$_POST["left"]."px; height:".$_POST["height"]."px; width:".$_POST["width"]."px; backgroud-color:blue;'>";
echo "</div>";
}
}
?>
  #8 (permalink)  
Antiguo 22/05/2011, 13:41
Avatar de gildus  
Fecha de Ingreso: agosto-2003
Mensajes: 1.495
Antigüedad: 20 años, 8 meses
Puntos: 105
Respuesta: Creacion de div con valores de post

Holas,

Aqui el codigo:

Código PHP:
Ver original
  1. <?php
  2. if(!isset($_POST['top']))
  3. { ?>
  4.     <form name="form1" method="POST">
  5.         Top
  6.         <input type="text" name="top" />
  7.         <br />
  8.         Left
  9.         <input type="text" name="left" />
  10.         <br />
  11.         Width
  12.         <input type="text" name="width" />
  13.         <br />
  14.         Height
  15.         <input type="text" name="height" />
  16.         <br />
  17.         <input type="submit"/>
  18.     </form>
  19. <?php
  20. }
  21. else
  22. {   if(isset($_POST["top"]) && isset($_POST["left"]) && isset($_POST["width"]) && isset($_POST["height"]))
  23.     {   $top=trim($_POST["top"]);
  24.         $left= trim($_POST["left"]);
  25.         $width= trim($_POST["width"]);
  26.         $height= trim($_POST["height"]);
  27.         if(!is_numeric($top)) die('Top no es numerico');
  28.         if(!is_numeric($left)) die('Left no es numerico');
  29.         if(!is_numeric($width)) die('Width no es numerico');
  30.         if(!is_numeric($height)) die('Height no es numerico');
  31.        
  32.         echo "<div style = 'top:".$top."px; left:".$left."px; height:".$height."px; width:".$width."px; background-color:blue;'>";
  33.         echo "</div>";
  34.        
  35.        
  36.     }      
  37. }
  38. ?>


En tu estilo no existe backgroud-color sino background-color

Saludos
Gildus
__________________
.: Gildus :.
  #9 (permalink)  
Antiguo 22/05/2011, 14:09
 
Fecha de Ingreso: mayo-2011
Mensajes: 23
Antigüedad: 12 años, 10 meses
Puntos: 0
Respuesta: Creacion de div con valores de post

Gracias Gildus, no puedo creer lo que me faltaba. Hago una ultima consulta, para que el div o el resultado de una input me aparezca en la misma pagina del formulario que tendria que agregar a mi codigo? Muchas gracias nuevamente
  #10 (permalink)  
Antiguo 22/05/2011, 15:03
Avatar de gildus  
Fecha de Ingreso: agosto-2003
Mensajes: 1.495
Antigüedad: 20 años, 8 meses
Puntos: 105
Respuesta: Creacion de div con valores de post

Mas o menos asi te refieres?:

Código PHP:
Ver original
  1. <form name="form1" method="POST">
  2.         Top
  3.         <input type="text" name="top" value="<? if(isset($_POST['top'])) echo $_POST['top']; ?>" />
  4.         <br />
  5.         Left
  6.         <input type="text" name="left" value="<? if(isset($_POST['left'])) echo $_POST['left']; ?>" />
  7.         <br />
  8.         Width
  9.         <input type="text" name="width" value="<? if(isset($_POST['width'])) echo $_POST['width']; ?>" />
  10.         <br />
  11.         Height
  12.         <input type="text" name="height" value="<? if(isset($_POST['height'])) echo $_POST['height']; ?>" />
  13.         <br />
  14.         <input type="submit"/>
  15.     </form>
  16. <br /><br />
  17. <?php
  18. if(isset($_POST["top"]) && isset($_POST["left"]) && isset($_POST["width"]) && isset($_POST["height"]))
  19. {   $top=trim($_POST["top"]);
  20.     $left= trim($_POST["left"]);
  21.     $width= trim($_POST["width"]);
  22.     $height= trim($_POST["height"]);
  23.     if(!is_numeric($top)) die('Top no es numerico');
  24.     if(!is_numeric($left)) die('Left no es numerico');
  25.     if(!is_numeric($width)) die('Width no es numerico');
  26.     if(!is_numeric($height)) die('Height no es numerico');
  27.    
  28.     echo "<div style = 'top:".$top."px; left:".$left."px; height:".$height."px; width:".$width."px; background-color:blue;'>";
  29.     echo "</div>";
  30.    
  31.    
  32. }      
  33. ?>


Saludos
Gildus
__________________
.: Gildus :.
  #11 (permalink)  
Antiguo 22/05/2011, 15:05
Avatar de gildus  
Fecha de Ingreso: agosto-2003
Mensajes: 1.495
Antigüedad: 20 años, 8 meses
Puntos: 105
Respuesta: Creacion de div con valores de post

Un punto al Karma no estaria mal. ;)
__________________
.: Gildus :.

Etiquetas: post
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 03:27.