Foros del Web » Programando para Internet » PHP »

Problema al añadir nuevos campos a formulario PHP

Estas en el tema de Problema al añadir nuevos campos a formulario PHP en el foro de PHP en Foros del Web. Hola buenas; Tengo una web en Wordpress en la cual tengo un formulario de contacto. Tengo que añadir unos campos a un formulario, el cual ...
  #1 (permalink)  
Antiguo 22/06/2011, 13:54
 
Fecha de Ingreso: noviembre-2007
Mensajes: 32
Antigüedad: 16 años, 5 meses
Puntos: 2
Problema al añadir nuevos campos a formulario PHP

Hola buenas;

Tengo una web en Wordpress en la cual tengo un formulario de contacto.

Tengo que añadir unos campos a un formulario, el cual hasta el momento solo tenía 3, nombre, email y mensaje (ahora tendrá además empresa y teléfono)

En el formulario ya he añadido los input pero en el archivo post.php que es el que procesa el formulario no logro que lleguen al correo esos nuevos campos. No soy ningún experto en PHP así que me imagino que será algo evidente pero llevo un tiempo mirándolo y la verdad es que no soy capaz.

Os pongo el código del archivo post.php:

Código PHP:
<?php

// CONFIGURATION --------------------------------------------------------------

// This is the email where the contact mails will be sent to. 
// In WordPress Edition, it will be done via the theme admin. You don't need to modify this file under WP Edition.
$config['recipient'] = isset($_POST['c_email']) ? trim($_POST['c_email']) : '';

// This is the subject line for contact emails.
// The variable %name% will be replaced with the name of the sender.
$config['subject'] = 'Nuevo mensaje desde la web de: %name%';

// These are the messages displayed in case of form errors.
$config['errors'] = array
(
    
'no_name'       => 'El nombre est&aacute; vac&iacute;o',
    
'no_email'      => 'El e-mail est&aacute; vaci&iacute;o',
    
'invalid_email' => 'Direcci&oacute;n de e-mail no v&aacute;lida',
    
'no_message'    => 'El mensaje est&aacute; vac&iacute;o',
);

// END OF CONFIGURATION -------------------------------------------------------


// Ignore non-POST requests
if ( ! $_POST)
    exit(
'Por favor, vuelve a la ra&iacute;z del sitio web.');

// Was this an AJAX request or not?
$ajax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');

// Set the correct HTTP headers
header('Content-Type: text/'.($ajax 'plain' 'html').'; charset=utf-8');

// Extract and trim contactform values
$name    = isset($_POST['name']) ? trim($_POST['name']) : '';
$email   = isset($_POST['email']) ? trim($_POST['email']) : '';
$empresa   = isset($_POST['empresa']) ? trim($_POST['empresa']) : '';
$telefono   = isset($_POST['telefono']) ? trim($_POST['telefono']) : '';
$message = isset($_POST['message']) ? trim($_POST['message']) : '';

// Take care of magic quotes if needed (you really should have them disabled)
if (get_magic_quotes_gpc())
{
    
$name    stripslashes($name);
    
$email   stripslashes($email);
    
$empresa   stripslashes($empresa);
    
$telefono   stripslashes($telefono);
    
$message stripslashes($message);
}

// Initialize the errors array which will also be sent back as a JSON object
$errors NULL;

// Validate name
if ($name == '' || strpos($name"\r") || strpos($name"\n"))
{
    
$errors['name'] = $config['errors']['no_name'];
}

// Validate email
if ($email == '')
{
    
$errors['email'] = $config['errors']['no_email'];
}
elseif ( ! 
preg_match('/^[-_a-z0-9\'+*$^&%=~!?{}]++(?:\.[-_a-z0-9\'+*$^&%=~!?{}]+)*+@(?:(?![-.])[-a-z0-9.]+(?<![-.])\.[a-z]{2,6}|\d{1,3}(?:\.\d{1,3}){3})(?::\d++)?$/iD'$email))
{
    
$errors['email'] = $config['errors']['invalid_email'];
}

// Validate message
if ($message == '')
{
    
$errors['message'] = $config['errors']['no_message'];
}

// Validation succeeded
if (empty($errors))
{
    
// Prepare subject line
    
$subject str_replace('%name%'$name$config['subject']);

    
// Additional mail headers
    
$headers  'Content-Type: text/plain; charset=utf-8'."\r\n";
    
$headers .= 'From: '.$email;

    
// Send the mail
    
if ( ! mail($config['recipient'], $subject$message$headers))
    {
        
$errors['server'] = 'Parece que existen problemas t&eacute;cnicos con nuestro servidor. Por favor, vuelve a probar pasados unos minutos. '.
                            
'Si lo prefieres, puedes enviarnos un mail a '.$config['recipient'].'.Muchas gracias.';
    }
}

if (
$ajax)
{
    
// Output the possible errors as a JSON object
    
echo json_encode($errors);
}
else
{
    
// Show a simple HTML feedback message in case of non-javascript support
    
if (empty($errors))
    {
        echo 
'<h4>Muchas gracias!</h4>';
        echo 
'<p>Tu mensaje ha sido enviado con &eacute;xito. Nos pondremos en contacto tan pronto nos sea posible.</p>';
    }
    else
    {
        echo 
'<h4>Oops!</h4>';
        echo 
'<p>Por favor, vuelve atr&aacute;s y comprueba los siguientes errores:</p>';
        echo 
'<ul><li>';
        echo 
implode('</li><li>'$errors);
        echo 
'</li></ul>';
    }
}

?>
El problema es que únicamente me llega al correo el nombre, el mail, y en el cuerpo del mail únicamente el mensaje, cuando lo que quiero que me llegue además de éste es la empresa y el teléfono.

Espero haberme explicado bien.

Muchas gracias y un saludo!

mnieto
  #2 (permalink)  
Antiguo 22/06/2011, 15:01
Avatar de aldairlinux  
Fecha de Ingreso: mayo-2011
Mensajes: 21
Antigüedad: 13 años
Puntos: 0
Respuesta: Problema al añadir nuevos campos a formulario PHP

Rebisa los nombre de los campos en el formulario si son iguales a como los definiste en post.php !
  #3 (permalink)  
Antiguo 22/06/2011, 15:09
 
Fecha de Ingreso: noviembre-2007
Mensajes: 32
Antigüedad: 16 años, 5 meses
Puntos: 2
Respuesta: Problema al añadir nuevos campos a formulario PHP

Muy buenas;

Gracias por la respuesta, los campos sí que se llaman igual. Os pongo el código por si acaso:

Código PHP:
<?php
    
    
///////////////////////////////////
    ///////////////////////////////////
    //// THIS WILL HANDLE THE SHORTCODES
    //// FOR PORTFOLIO
    ///////////////////////////////////
    ///////////////////////////////////
    
    //Our hook
    
add_shortcode('contact_form''ddshort_contact_form');
    
    
//Our Funciton
    
function ddshort_contact_form($atts$content null) {
        
        
//extracts our attrs . if not set set default
        
extract(shortcode_atts(array(
        
            
'email' => get_option('admin_email')
        
        ), 
$atts));
        
        
$output '
        <form id="contactform" action="'
.get_bloginfo('template_url').'/includes/mail/post.php" method="post" enctype="multipart/form-data"> 
            <fieldset>
                <div class="input-div">
                    <label for="name">Nombre <span class="naranja_fuerte_negrita">*</span>
                        <input type="text" id="name" name="name" maxlength="75" value="" tabindex="1" />
                     </label>
                     <label for="email">Email <span class="naranja_fuerte_negrita">*</span>
                           <input type="text" id="email" name="email" maxlength="75" value="" tabindex="2" />
                     </label>
                    <label for="empresa">Empresa
                        <input type="text" id="empresa" name="empresa" maxlength="75" value="" tabindex="3" />
                     </label>
                    <label for="telefono">Tel&eacute;fono
                        <input type="text" id="telefono" name="telefono" maxlength="9" value="" tabindex="4" />
                     </label>
                </div>
                  <div class="message-div">
                    <label for="message">Mensaje <span class="naranja_fuerte_negrita">*</span>
                        <textarea id="message" name="message" cols="20" rows="5" tabindex="5"></textarea>
                    </label>
                    <input type="submit" class="submit" value="enviar" />
                    <input type="hidden" name="c_email" id="c_email" value="'
.$email.'" />
                  </div>
            </fieldset>          
        </form>'
;                                        
        return 
$output;
    }
    
    include(
'tinyMCE.php');

?>
Saludos!

Etiquetas: formulariophp, php+ajax+formularios, formulario
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 12:00.