Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Form Validation for Phone Field

$
0
0

Hello,

I'm creating a form using code I obtained from an online tutorial.  It works perfectly and validates as it should.  I would like to add a "phone" field which would also need validation.  So far I have not been able to get the field to validate.  What am I missing??  I've included the parts of the php that I changed and also attached my javascript validation file as a text file.  Here is a link to the page the form is on: http://www.idealwindow.com/Contact_Marketing.php  

Thanks for any help you can offer.

 

In the head tag:

<script type="text/javascript" src="js/validation.js"></script>
<script type="text/javascript">
var nameError = '<?php echo $error_messages['fullname']; ?>';
var phoneError = '<?php echo $error_messages['phone']; ?>';
var emailError = '<?php echo $error_messages['email']; ?>';
var commentError = '<?php echo $error_messages['comment']; ?>';
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
    </script>
 
 
In the body tag:
 


<div class="row">
    <div class="label">Full Name</div><!-- end .label -->
    <div class="input">
    <input type="text" id="fullname" class="detail" name="fullname" value="<?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''; ?>" /><?php if(in_array('fullname', $validation)): ?><span class="error"><?php echo $error_messages['fullname']; ?></span><?php endif; ?>
    </div><!-- end .input -->
    <div class="context">e.g. John Smith or Jane Doe</div><!-- end .context -->
    </div><!-- end .row -->
    
    <div class="row">
    <div class="label">Phone</div><!-- end .label -->
    <div class="input">
   <input type="text" id="phone" class="detail" name="phone" value="<?php echo isset($_POST['phone'])? $_POST['phone'] : ''; ?>" /><?php if(in_array('phone', $validation)): ?><span class="error"><?php echo $error_messages['phone']; ?></span><?php endif; ?>
    </div><!-- end .input -->
     <div class="context">e.g. 000-000-0000</div><!-- end .context -->
    </div><!-- end .row -->

Attached Files


Viewing all articles
Browse latest Browse all 13200

Trending Articles