Foros del Web » Programando para Internet » PHP »

error en strstr

Estas en el tema de error en strstr en el foro de PHP en Foros del Web. hola chicos aca tengo un error que me no e determinado la problematica del el. estoy creando un formulario el cual no quiero usar html ...
  #1 (permalink)  
Antiguo 21/09/2011, 10:56
 
Fecha de Ingreso: abril-2010
Mensajes: 151
Antigüedad: 14 años
Puntos: 1
error en strstr

hola chicos aca tengo un error que me no e determinado la problematica del el.
estoy creando un formulario el cual no quiero usar html si no funciones el cual e creado algunas

Código PHP:

function formOpen($action NULL$class "forms"$ID NULL$legend NULL$method "post"$enctype "multipart/form-data") {    
    
$ID     = (isset($ID))     ? ' id="'$ID .'"'                            NULL;
    
$legend = (isset($legend)) ? "<legend>$legend</legend>" "\n" NULL;
    
$action = (strstr($action"http://")) ? $action _url $action;
    
    
$HTML  '<form'$ID .' action="'$action .'" method="'$method .'" class="'$class .'" enctype="'$enctype .'">' "\n\t";
    
$HTML .= '<fieldset>' "\n\t\t";
    
$HTML .= $legend "\n";            

    return 
$HTML;
}


function 
formClose() {
    
$HTML  "\t" "</fieldset>" "\n";
    
$HTML .= "</form>";        
    
    return 
$HTML;

esas dos funciones deberian de crearme esto

<form action="" method="POST">

</form>

atraves de una arreglo que lo hago asi

Código PHP:
$login = array("action" => """method" => "post",);
print 
formOpen($login);

print 
formClose(); 

dandome este error Warning: strstr() expects parameter 1 to be string, array given in C:\xampp\htdocs\redsocial.com\system\helpers\forms .php on line 145
  #2 (permalink)  
Antiguo 21/09/2011, 11:10
 
Fecha de Ingreso: agosto-2011
Ubicación: DF
Mensajes: 44
Antigüedad: 12 años, 8 meses
Puntos: 10
Respuesta: error en strstr

probe tu codigo agregandole una linea y poniendole un valor y jala muy bien

Código PHP:
Ver original
  1. <?
  2.  
  3. function formOpen($action = NULL, $class = "forms", $ID = NULL, $legend = "hola", $method = "post", $enctype = "multipart/form-data") {    
  4.     $ID     = (isset($ID))     ? ' id="'. $ID .'"'                            : NULL;
  5.     $legend = (isset($legend)) ? "<legend>$legend</legend>" . "\n" : NULL;
  6.     $action = (strstr($action, "http://")) ? $action : _url . $action;
  7.      
  8.     $HTML  = '<form'. $ID .' action="'. $action .'" method="'. $method .'" class="'. $class .'" enctype="'. $enctype .'">' . "\n\t";
  9.     $HTML .= '<fieldset>' . "\n\t\t";
  10.     $HTML .= $legend . "\n";
  11.     $HTML .= '<input type="submit" value="boton"/>';            
  12.  
  13.     return $HTML;
  14. }
  15.  
  16.  
  17. function formClose() {
  18.     $HTML  = "\t" . "</fieldset>" . "\n";
  19.     $HTML .= "</form>";        
  20.      
  21.     return $HTML;
  22. }  
  23.  
  24. $login = array("action" => "ard.php", "method" => "post",);
  25. echo formOpen($login);
  26.  
  27. echo formClose();
  28.  
  29.  
  30. ?>
  #3 (permalink)  
Antiguo 21/09/2011, 11:15
Avatar de andresdzphp
Colaborador
 
Fecha de Ingreso: julio-2011
Ubicación: $this->Colombia;
Mensajes: 2.749
Antigüedad: 12 años, 9 meses
Puntos: 793
Respuesta: error en strstr

El error es claro y ambos están cometiendo el mismo error:

Warning: strstr() expects parameter 1 to be string, array given

No le puedes pasar un array a la función strstr()

Además debes ordenar los parámetros.
__________________
Si sabemos como leer e interpretar el manual será mucho más fácil aprender PHP. En lugar de confiar en ejemplos o copiar y pegar - PHP
  #4 (permalink)  
Antiguo 21/09/2011, 11:25
 
Fecha de Ingreso: septiembre-2011
Ubicación: DF
Mensajes: 26
Antigüedad: 12 años, 7 meses
Puntos: 6
Respuesta: error en strstr

Tu error esta en que tu funcion formOpen estas recibiendo varios parametros no un array como lo quieres utilizar.


tienes de 2 procesar el arreglo asociativo con los parametros que quieres

ó cuando llames a tu funcion en lugar de hacer esto
Código PHP:
print formOpen($login); 
hacer
Código PHP:
print formOpen($parametro1,$parametro2,$parametro3 ...); 
y en esta linea te falta el segundo parametro y el ; :

$ID = (isset($ID)) ? ' id="'. $ID .'"'

$ID = (isset($ID)) ? ' id="'. $ID .'"': '';



espero haberme explicado saludos
  #5 (permalink)  
Antiguo 21/09/2011, 12:59
 
Fecha de Ingreso: abril-2010
Mensajes: 151
Antigüedad: 14 años
Puntos: 1
Respuesta: error en strstr

hice asi :) y se soluciono el problema
Código PHP:
Ver original
  1. $attributes = array("id" => "login",
  2.         "action" => "javascript:cuentas.login_ajax()",
  3.         "method" => "post",
  4.         "class" => "form",
  5.         "enctype" => "multipart/form-data");
  6.      $legend = "Form";
  7. print formOpen(is_array($attributes), $legend);
  #6 (permalink)  
Antiguo 21/09/2011, 13:11
Avatar de andresdzphp
Colaborador
 
Fecha de Ingreso: julio-2011
Ubicación: $this->Colombia;
Mensajes: 2.749
Antigüedad: 12 años, 9 meses
Puntos: 793
Respuesta: error en strstr

Pues no veo en que solucione el problema, estás pasando como parámetro true a la función formOpen

is_array($attributes) = true...

Lo único que te funciona son los parámetros por defecto.
__________________
Si sabemos como leer e interpretar el manual será mucho más fácil aprender PHP. En lugar de confiar en ejemplos o copiar y pegar - PHP
  #7 (permalink)  
Antiguo 21/09/2011, 14:13
 
Fecha de Ingreso: abril-2010
Mensajes: 151
Antigüedad: 14 años
Puntos: 1
Respuesta: error en strstr

tenias razon edito andresdzphp tiene la razon pero mifique un poco el codigo

Código PHP:
Ver original
  1. public static function open ($action = NULL, $method = 'post', $attrs = NULL)
  2.     {
  3.         if (is_array($attrs)) {
  4.             $attrs = getAtrs($attrs);
  5.         }
  6.         if ($action) {
  7.             $action =  $action;
  8.         }
  9.         return "<form action=\"$action\" method=\"$method\" $attrs>";
  10.     }
  11.  
  12.  /**
  13.      * Etiqueta para cerrar un formulario
  14.      *
  15.      * @return string
  16.      */
  17.     public static function close ()
  18.     {
  19.         self::$_multipart = FALSE;
  20.         return '</form>';
  21.     }

ejemplo

Código PHP:
Ver original
  1. <div align="center" id="loginbox">  
  2.  
  3. <?php
  4. print form::open('javascript:cuentas.login_ajax();');
  5. ?>
  6.  
  7.  <small><?php echo  $this->lang->lang('user'); ?>:</small>
  8.  <?php
  9.                                        $attributes = array("name" => "usuario",
  10.                                            "class" => "loginput blur",
  11.                                            "type" => "text",
  12.                                            "placeholder" => $this->lang->lang('user'),
  13.                                            "id" => "usuario"
  14.                                            );
  15.                                        print form::formInput($attributes);
  16.  ?>                                      
  17.   <table width="300">
  18.   <tbody><tr><td align="left">
  19.  <small><?php echo  $this->lang->lang('pass'); ?>:</small></td></tr><tr></tr></tbody></table>
  20.  <?php
  21.                                        $attributes = array("name" => "password",
  22.                                            "class" => "loginput blur",
  23.                                            "type" => "password",
  24.                                            "placeholder" => $this->lang->lang('pass'),
  25.                                            "id" => "password"
  26.                                            );
  27.                                        print form::formInput($attributes);
  28.  ?>  
  29.  
  30.  <br>
  31.  <table height="40" width="300">
  32.  <tbody><tr> <td align="left">
  33.              <?php
  34.                                        $attributes = array(
  35.                                            "class" => "loginbtn",
  36.                                            "type" => "submit",
  37.                                            "value" => "&radic; Entrar"
  38.                                            );
  39.                                        print form::formInput($attributes);
  40.  ?>  
  41.  
  42.   </td> <td align="right">   <input type="checkbox" id="rem" name="rem" value="true" checked="checked" />
  43.  <span><?php echo  $this->lang->lang('reminder'); ?></span></td> </tr><tr></tr></tbody></table>
  44.  <div class="klear"></div>
  45.  
  46.  <?php print form::close(); ?>
  #8 (permalink)  
Antiguo 21/09/2011, 14:15
 
Fecha de Ingreso: abril-2010
Mensajes: 151
Antigüedad: 14 años
Puntos: 1
Respuesta: error en strstr

el cual me imprime esto ;) saludos espero este bien

Código PHP:
Ver original
  1. <form action="javascript:cuentas.login_ajax();" method="post" >
  2.  <small>Usuario:</small>
  3.  <input name="usuario" class="loginput blur" placeholder="Usuario" id="usuario" type="text" />
  4.                                      
  5.   <table width="300">
  6.   <tbody><tr><td align="left">
  7.  <small>Contrase&ntilde;a:</small></td></tr><tr></tr></tbody></table>
  8.  <input name="password" class="loginput blur" placeholder="Contrase&ntilde;a" id="password" type="password" />
  9.  
  10.  
  11.  <br>
  12.  <table height="40" width="300">
  13.  <tbody><tr> <td align="left">
  14.              <input class="loginbtn" value="&radic; Entrar" type="submit" />
  15.  
  16.  
  17.   </td> <td align="right">   <input type="checkbox" id="rem" name="rem" value="true" checked="checked" />
  18.  <span>No cerrar Sesi&oacute;n</span></td> </tr><tr></tr></tbody></table>
  19.  <div class="klear"></div>
  20.  
  21.  </form>

Etiquetas: formulario, login.php, loginajax, phpmysql
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 16:16.