Foros del Web » Creando para Internet » Sistemas de gestión de contenidos » WordPress »

Problema enviando formulario

Estas en el tema de Problema enviando formulario en el foro de WordPress en Foros del Web. Hola a todos, Tengo el siguiente formulario Template en my tema de wordpress para agregar un formulario al final de mi pagina de contacto: Código ...
  #1 (permalink)  
Antiguo 14/09/2010, 23:46
 
Fecha de Ingreso: junio-2009
Mensajes: 79
Antigüedad: 14 años, 10 meses
Puntos: 0
Pregunta Problema enviando formulario

Hola a todos,

Tengo el siguiente formulario Template en my tema de wordpress para agregar un formulario al final de mi pagina de contacto:

Código PHP:
<?php
/**
 * Template Name: Contact Template
 *
 */
if (isset($_POST['submit'])){
    
/**
     * Validar y enviar formulario
     */
    
if(trim($_POST['name']) === ''){
        
$nameError __('Please enter your name.');
        
$hasError true;
    } else {
        
$name trim($_POST['name']);
    }

    if(
trim($_POST['email']) === ''){
        
$emailError __('Please enter your email.');
        
$harError true;
    } elseif(!
eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$"trim($_POST['email']))) {
        
$emailError __('Please enter a valid email address.');
        
$harError true;
    } else {
        
$email trim($_POST['email']);
    }

    if(
trim($_POST['zip']) === ''){
        
$zipError __('Please enter your zip code.');
        
$hasError true;
    } else {
        
$zip trim($_POST['zip']);
    }

    if(!(
trim($_POST['address']) === '')){
        
$address trim($_POST['address']);
    } else {
        
$address 'N/A';
    }

    if(!(
trim($_POST['company']) === '')){
        
$company trim($_POST['company']);
    } else {
        
$company 'N/A';
    }

    if(!(
trim($_POST['city']) === '')){
        
$city trim($_POST['city']);
    } else {
        
$address 'N/A';
    }

    if(!(
trim($_POST['state']) === '')){
        
$state trim($_POST['state']);
    } else {
        
$state 'N/A';
    }

    if(!(
trim($_POST['phone']) === '')){
        
$phone trim($_POST['phone']);
    } else {
        
$phone 'N/A';
    }

    if(!isset(
$hasError)){
        
$emailTo "[email protected]";
        
$subject "[Contact Form] From: " $name;
        
$body "Name: " $name "\n\n";
        
$body .= "Email: " $email "\n\n";
        
$body .= "Company: " $company "\n\n";
        
$body .= "Address: " $address "\n\n";
        
$body .= "City: " $city "\n\n";
        
$body .= "State: " $state "\n\n";
        
$body .= "Zip: " $zip "\n\n";
        
$body .= "Phone: " $phone "\n\n";
        
$headers 'From: '.$name.' <'.$emailTo.'>' "\r\n" 'Reply-To: ' $email;

        if(
mail($emailTo$subject$body$headers)){
            
$emailSent true;
        }
    }
}
get_header(); ?>

        <div id="container" class="one-column">
            <div id="content" role="main">

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

                <div id="post-<?php the_ID(); ?><?php post_class(); ?>>
                                    <?php if (!is_page ()): ?>
                    <h1 class="entry-title"><?php the_title(); ?></h1>
                                    <?php endif; ?>
                    <div class="entry-content">
                        <?php the_content(); ?>
                    </div><!-- .entry-content -->
                </div><!-- #post-## -->

<?php endwhile; ?>
                            <p>
                                <?php _e('* Important: At this time we only service small to medium businesses with
                                at least 5 or more PCs. We do not service home users.'
); ?>
                            </p>
                            <p>
                                <?php _e('Fields in '); ?><span class="red"><?php _e('RED'); ?></span><?php _e(' are required.'); ?>
                            </p>
                            <div id="form-area">
                                <?php if (isset($emailSent) && $emailSent == true): ?>
                                <div id="success">
                                    <p><?php _e('Thanks, your email was sent successfully.'); ?></p>
                                </div>
                                <?php else : ?>
                                <?php if (isset($hasError)): ?>
                                <div class="error">
                                    <p><?php _e('Sorry an error ocurred.'); ?></p>
                                </div>
                                <?php endif; ?>
                                <form action="<?php the_permalink(); ?>" method="post" id="contact-form" name="contact-form">
                                    <table>
                                        <tr>
                                            <td><label class="red" for="email"><?php _e('Email'); ?></label></td>
                                            <td>
                                                <input type="text" name="email" id="email" value="<?php if (isset($_POST['email'])) echo $_POST['email']; ?>" />
                                                <?php if ($emailError != ''): ?>
                                                <span class="error red"><?php echo $emailError?></span>
                                                <?php endif; ?>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td><label class="red" for="name"><?php _e('Contact Name'); ?></label></td>
                                            <td>
                                                <input type="text" name="name" id="name" value="<?php if (isset($_POST['name'])) echo $_POST['name']; ?>" />
                                                <?php if ($nameError != ''): ?>
                                                <span class="error red"><?php echo $nameError?></span>
                                                <?php endif; ?>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td><label for="company"><?php _e('Company'); ?></label></td>
                                            <td><input type="text" name="company" id="company" value="<?php if (isset($_POST['company'])) echo $_POST['company']; ?>" /></td>
                                        </tr>
                                        <tr>
                                            <td><label for="address"><?php _e('Address'); ?></label></td>
                                            <td><input type="text" name="address" id="address" value="<?php if (isset($_POST['address'])) echo $_POST['address']; ?>" /></td>
                                        </tr>
                                        <tr>
                                            <td><label for="city"><?php _e('City'); ?></label></td>
                                            <td><input type="text" name="city" id="city" value="<?php if (isset($_POST['city'])) echo $_POST['city']; ?>" /></td>
                                        </tr>
                                        <tr>
                                            <td><label for="state"><?php _e('State'); ?></label></td>
                                            <td><input type="text" name="state" id="state" value="<?php if (isset($_POST['state'])) echo $_POST['state']; ?>" /></td>
                                        </tr>
                                        <tr>
                                            <td><label class="red" for="zip"><?php _e('Zip Code'); ?></label></td>
                                            <td>
                                                <input type="text" name="zip" id="zip" size="5" value="<?php if (isset($_POST['zip'])) echo $_POST['zip']; ?>" />
                                                <?php if ($zipError != ''): ?>
                                                <span class="error red"><?php echo $zipError?></span>
                                                <?php endif; ?>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td><label for="phone"><?php _e('Phone'); ?></label></td>
                                            <td><input type="text" name="phone" id="phone" value="<?php if (isset($_POST['phone'])) echo $_POST['phone']; ?>" /></td>
                                        </tr>
                                        <tr>
                                            <td></td>
                                            <td><input type="submit" name="submit" id="submit" value="<?php _e('Submit'); ?>" /></td>
                                        </tr>
                                    </table>
                                </form>
                                <?php endif; ?>
                            </div>
            </div><!-- #content -->
        </div><!-- #container -->

<?php get_footer(); ?>
Disculpen lo largo pero no sabia en que lugar podria estar el error asi que lo copie todo. Las validaciones las aplica correctamente pero cuando toda la informacion es valida en vez de enviar el formulario me muestra una pagina de 404 o no encontrada.

Alguien sabe que puede estar pasando? Gracias de antemano.
  #2 (permalink)  
Antiguo 15/09/2010, 00:38
 
Fecha de Ingreso: junio-2009
Mensajes: 79
Antigüedad: 14 años, 10 meses
Puntos: 0
Respuesta: Problema enviando formulario

Ya lo resolvi, el problema era el input con el nombre "name" se lo cambie a "clientName" y todo perfecto, aunque no se porque no me funcionaba asi :s

Etiquetas: 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:59.