Foros del Web » Programando para Internet » PHP »

extraer variables y enviar formulario

Estas en el tema de extraer variables y enviar formulario en el foro de PHP en Foros del Web. Hola, estoy aprendiendo un poco php, y he modificado un formulario en HTML5 que me ha quedado así: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código HTML: Ver original < ...
  #1 (permalink)  
Antiguo 02/10/2012, 14:15
 
Fecha de Ingreso: marzo-2008
Ubicación: España
Mensajes: 243
Antigüedad: 16 años, 1 mes
Puntos: 7
extraer variables y enviar formulario

Hola, estoy aprendiendo un poco php, y he modificado un formulario en HTML5 que me ha quedado así:

Código HTML:
Ver original
  1. <form method="post" action="enviar.php">
  2.  
  3.            
  4. <!--  <input type="hidden" name="asuntooculto" value="asuntooculto"> -->
  5. <!-- no funciona $subject = jayj_html5_sanitize_string( $_REQUEST['asuntooculto'] ); -->
  6. <!--  tampoco funciona if ( mail( $email, "$subject (Asunto personalizado)",   -->
  7.          
  8. <label for="nombre2">Nombre:</label><input type="text" name="nombre" id="nombre2" value=""><br>
  9. <label for="email2">Email*:</label><input type="text" name="email" id="email2" value=""><br><br>
  10. <label for="subject2">Asunto:</label><input type="text" name="subject" id="subject2" value=""><br><br>
  11.  
  12. <label for="texto2">Texto 1:</label><input type="text" name="texto-primero" id="texto2" value=""><br>
  13. <label for="texto3">Texto 2:</label><input type="text" name="texto-segundo" id="texto3" value=""><br><br>
  14.  
  15. <label  for="menuselect2">Seleccionar</label>
  16. <select name="menuselect">
  17. <option value ="opcion1" selected>Primera</option>
  18. <option value ="opcion2">Segunda</option>
  19. <option value ="opcion3">Tercera</option>
  20. <option value ="opcion4">Cuarta</option>
  21.  
  22. <label for="fecha2">Fecha start:</label><input type="date" name="fecha-primero" id="fecha2"><br>
  23. <label for="fecha3">Fecha end:</label><input type="date" name="fecha-segundo" id="fecha3"><br>
  24. <label for="numero2">Numero:</label><input type="text" name="numero" id="numero2" value=""><br>
  25.  
  26. <label for="mensaje2">Texto mensaje*:<br></label><textarea name="mensaje" id="mensaje2" cols="45" rows="5"></textarea><br>
  27.  
  28. <button type="submit" value="submit">Enviar formulario</button>
  29.  
  30. </form>

Pasa que al querer extraer las variables con enviar.php, sólo me funciona el envío del mail con la sentencia original o agregado una sola variable más. Luego aparentemente, agregado una sola variable una por una, funciona con todas, pero no juntas. La sentencia original es:
Código PHP:
 if ( mail$email"$subject",  utf8_decode$message ), "From: $name < $sender>" ) ) 
y no con la cadena completa como quiero:
Código PHP:
if ( mail$email"$subject"$texto1$texto2$menuselect$fechastart$fechaend$numeroutf8_decode$message ), "From: $name < $sender>" ) ) 
El Error es Warning: mail() expects at most 5 parameters, 10 given in .../enviar.php on line 90 (es decir la línea de arriba)

Además, querría poner un asunto predefinido y esconder el campo Asunto en el formulario, pero no hay manera, he intentado con $_REQUEST['asuntooculto'] estando el input del asunto hidden, como pueden ver en el archivo enviar.php:

Código PHP:
<?php
/**
 * PHP contact form
 */

// If the form have been submitted and the spam check field is empty
if ( isset( $_POST['email'] ) && empty( $_POST['s_check'] ) ) :

    
/**
     * Enter your email here
     */
    
$email '[email protected]';

    
/**
     * Language strings
     */
    
$strings = array(
        
'default_subject' => 'Message on your website',
        
'default_name'    => 'Anonymous',
        
'error_message'   => '<strong>Error:</strong> %s cannot be left blank'// %s is the error name
        
'invalid_email'   => '<strong>Error:</strong> Email address is invalid',
        
'email_success'   => 'Gracias! hemos recibido su mensaje',
        
'email_error'     => 'There was a problem sending your email. Please try again'
    
);

    
/**
     * Required fields
     * We'll check and see if any of the required fields are empty.
     */
    
$required = array(
        
//'name'    => 'Name',
        //'subject' => 'Subject',
        
'email'   => 'Email',
        
'mensaje' => 'Message'
    
);

    
// Declare our $errors variable we will be using later to store any errors.
    
$errors = array();

    
/**
     * Get form values and sanitize them
     */
    
$name    jayj_html5_sanitize_string$_POST['nombre'] );
    
$from    filter_var$_POST['email'], FILTER_SANITIZE_EMAIL );
    
$subject jayj_html5_sanitize_string$_POST['subject'] );
    
//$subject = jayj_html5_sanitize_string( $_REQUEST['asuntooculto'] );
    //$subject = 'Asunto personalizado tampoco funciona';    

    
$texto1 jayj_html5_sanitize_string$_POST['texto-primero'] );
    
$texto2 jayj_html5_sanitize_string$_POST['texto-segundo'] );
    
$menuselect jayj_html5_sanitize_string$_POST['menuselect'] );
    
$fechastart jayj_html5_sanitize_string$_POST['fecha-primero'] );
    
$fechaend jayj_html5_sanitize_string$_POST['fecha-segundo'] );
    
$numero jayj_html5_sanitize_string$_POST['numero'] );    
    
    
$message jayj_html5_sanitize_string$_POST['mensaje'] );    
    
$sender '[email protected]'// or another email from your own domain
    
$message .= "\n Sent from: $from";
    
    
    
// Validate the sanitized email
    
if ( ! filter_var$fromFILTER_VALIDATE_EMAIL ) )
           
$errors[] = $strings['invalid_email'];

    
// Set a default name
    
if ( empty( $name ) )
        
$name $strings['default_name'];

    
// Set a default subject
    
if ( empty( $subject ) )
        
$subject $strings['default_subject'];

    
/**
     * Loops through each required $_POST value
     * Checks to ensure it is not empty.
     */
    
foreach ( $required as $key => $value ) :
        if ( isset( 
$_POST[$key] ) && ! empty( $_POST[$key] ) )
            continue;
        else
            
$errors[] = sprintf$strings['error_message'], $value );
    endforeach;

    
/**
     * Now check to see if there are any errors
     */
    
if ( empty( $errors ) ) {

        
// No errors, send mail using conditional to ensure it was sent.
        
if ( mail$email"$subject"$texto1$texto2$menuselect$fechastart$fechaend$numeroutf8_decode$message ), "From: $name < $sender>" ) )
            echo 
'<p class="alert alert-success">' $strings['email_success'] . '</p>';
        else
            echo 
'<p class="alert alert-error">' $strings['email_error'] . '</p>';

    } else {
        
// Errors were found, output all errors to the user.
        
echo '<div class="alert alert-warning">';
            echo 
implode'<br />'$errors );
        echo 
'</div>';
    }

else :

    
// The user have tried to access thid page directly or is a spambot
    
die("You're not allowed to access this page directly");

endif;

/**
 * Sanitize inputs
 *
 * @uses  FILTER_SANITIZE_STRING         Strip tags
 * @uses  FILTER_FLAG_NO_ENCODE_QUOTES     Prevents encoding of quotes
 * @uses  stripslashes()                 Removes slashes added to quotes
 *
 * @since  Jayj HTML5 theme 2.1
 * @param  string  $string The string to be sanitized
 * @return string          The sanitized string
 */
function jayj_html5_sanitize_string$string ) {
    return 
stripslashesfilter_var$stringFILTER_SANITIZE_STRINGFILTER_FLAG_NO_ENCODE_QUOTES ) );
}

A ver si me podrían ayudar a recibir todos los parámetros por email y a poner un asunto personalizado quitando el input asunto. Gracias de antemano.

Última edición por maxtorplextor; 02/10/2012 a las 14:28
  #2 (permalink)  
Antiguo 02/10/2012, 14:59
Avatar de mauled  
Fecha de Ingreso: marzo-2005
Ubicación: Cd. de México.
Mensajes: 3.001
Antigüedad: 19 años, 1 mes
Puntos: 33
Respuesta: extraer variables y enviar formulario

Yo lo que te recomiendo es que revises los parametros que requiere mail()
  #3 (permalink)  
Antiguo 02/10/2012, 16:15
 
Fecha de Ingreso: marzo-2008
Ubicación: España
Mensajes: 243
Antigüedad: 16 años, 1 mes
Puntos: 7
Respuesta: extraer variables y enviar formulario

Cita:
Iniciado por mauled Ver Mensaje
Yo lo que te recomiendo es que revises los parametros que requiere mail()
Muchas gracias por tu atención y respuesta. Ya está 100% operativo, ahora entiendo mucho mejor que pasa por allí en esa linea... Pensé que podía ser kilométrica y no entendía muy bien el error a qué se debía. Saludos!

Etiquetas: formulario, html, variables
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 06:50.