form submission

hi guys,

i am 100% php newb, so please be patience with me

this code was used to get contact info and submit it via email …

i added “number” field, and the field shows up under the webpage, but for some reason it does not show up when user actually type in the digits and submits the form

any advise?

thanks in advance!!!

[php]<?php
/*
Template Name: Contact
*/
?>

<?php $numberError=''; $nameError=''; $emailError=''; $commentError=''; if(isset($_POST['submitted'])) { if(trim($_POST['contactName']) === '') { $nameError = 'Please enter your name.'; $hasError = true; } else { $name = trim($_POST['contactName']); } if(trim($_POST['email']) === '') { $emailError = 'Please enter your email address.'; $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) { $emailError = 'You entered an invalid email address.'; $hasError = true; } else { $email = trim($_POST['email']); } if(trim($_POST['comments']) === '') { $commentError = 'Please enter a message.'; $hasError = true; } else { if(function_exists('stripslashes')) { $comments = stripslashes(trim($_POST['comments'])); } else { $comments = trim($_POST['comments']); } } if(!isset($hasError)) { $emailTo = get_option('tz_email'); if (!isset($emailTo) || ($emailTo == '') ){ $emailTo = get_option('admin_email'); } $subject = '[Appointment Request] From '.$name; $body = "Name: $name \n\nEmail: $email \n\nComments: $comments \n\nNumber: $number "; $headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } } ?> <?php get_header(); ?>
<?php if (function_exists('inkthemes_breadcrumbs')) inkthemes_breadcrumbs(); ?>

<?php the_title(); ?>

    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
  • <?php if(isset($emailSent) && $emailSent == true) { ?>

    <?php _e('Thanks, your request was sent successfully.','colorway'); ?>

    <?php } else { ?> <?php the_content(); ?> <?php if(isset($hasError) || isset($captchaError)) { ?>

    <?php _e('Sorry, an error occured.','colorway'); ?>

    <?php } ?>

    • <?php _e('Name:','colorway'); ?> <?php if($nameError != '') { ?> <?php echo $nameError;?> <?php } ?>
    • <?php _e('Email:','colorway'); ?> <?php if($emailError != '') { ?> <?php echo $emailError;?> <?php } ?>
    • <?php _e('Phone Number:','colorway'); ?> <?php if($numberError != '') { ?> <?php echo $numberError;?> <?php } ?>
                <li>
                  <label for="commentsText"><?php _e('Please provide day, time, type of service desired:','colorway'); ?></label>
                  <textarea name="comments" id="commentsText" rows="20" cols="30" class="required requiredField"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?>
    
    <?php if($commentError != '') { ?> <?php echo $commentError;?> <?php } ?>
<?php } ?> <?php endwhile;?>
  </div>
  <div class="social_logo"> <a title="Tweet this!" href="http://twitter.com/home/?status=<?php the_title(); ?> : <?php the_permalink(); ?>"><img src="<?php echo get_template_directory_uri(); ?>/images/twitter-share.png" alt="twitter" title="twitter"/></a> <a title="Share on StumbleUpon!" href="http://www.stumbleupon.com/submit?url=<?php the_permalink(); ?>&amp;amp;title=<?php the_title(); ?>"><img src="<?php echo get_template_directory_uri(); ?>/images/stumbleupon.png" alt="upon" title="upon"/></a> <a title="Share on Facebook" href="http://www.facebook.com/sharer.php?u=<?php the_permalink();?>&amp;amp;t=<?php the_title(); ?>"><img src="<?php echo get_template_directory_uri(); ?>/images/facebook-share.png" alt="facebook" title="facebook"/></a> <a title="Digg This!" href="http://digg.com/submit?phase=2&amp;amp;url=<?php the_permalink(); ?>&amp;amp;title=<?php the_title(); ?>"><img src="<?php echo get_template_directory_uri(); ?>/images/digg-share.png" alt="digg" title="digg"/></a> </div>
  <div class="clear"></div>      
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>[/php]

OpzMaster: Surrounded the code in PHP format for better debugging!

Well, you did add a “number” field in your form. And, you use an undefined variable called “$number”.
You need to define the variable, it will not load itself. PHP code is done server-side, so your html form
for the number field runs client-side. You must pull the value into your $number variable.

As an example, you did this for $name like this:
$name = trim($_POST[‘contactName’]);

You must add something like this:
$number = trim($_POST[‘number’]);

So, that is what you are missing… Please remember that PHP is only server-side. It can “pull” data from a form that has been posted to the PHP code, but, it does NOT run client-side. If you “View-Source” of any page on the internet, you will never see any PHP code. (It disappears once it is processed!)

Hope that helps…

Thanks for the correction, I will try it first chance I get

Sponsor our Newsletter | Privacy Policy | Terms of Service