如何使用PHP验证表单并显示验证消息

时间:2016-01-19 11:13:46

标签: javascript php forms validation

我需要验证我的表单字段并使用PHP使用工具Tip显示它们。我在下面解释我的代码。

  

的index.php:

<form name="billdata" id="billdata"  enctype="multipart/form-data" >
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px"> Name :</span>
<input type="text" name="u_name" id="name" class="form-control" placeholder="Add Catagory">
</div> 
<span class="error" id="nameError" style="display:none;">* <?php echo $nameErr;?></span>
 <div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Email :</span>
<input type="email" name="u_email" id="emailid" class="form-control" placeholder="Add Email Id">
</div>
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Mobile No :</span>
<input type="text" name="u_mobile_no" id="mobno" class="form-control" placeholder="Add Mobile No">
 </div>
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">TYPE OF COMPLAINT
 :</span>
<select class="form-control"  id="compleant">
<option value="">Select types of complaint</option>
<option value="card">Card Related</option>
<option value="claim">Claim Related</option>
<option value="product">Product Related</option>
<option value="Premimum">Premimum Related</option>
</select>
</div>
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Upload Image :</span>

 <input type="file" class="filestyle form-control" data-size="lg" name="uploadme" id="bannerimage">
</div>
<div class="input-group bmargindiv1 text-right col-md-12" style="display:none;">
<img src="" name="pro" border="0" style="width:50px; height:50px; border:#808080 1px solid;" />
</div>
 <input type="button" class="btn btn-success" name="complainSubmit"  id="addProfileData" value="Add"/>
</form>

<?php
if(isset($_POST['complainSubmit']) || isset($_REQUEST['appsubmit']))
{
        $name=$_REQUEST['u_name'];


}
?>

在上面的代码中我需要当用户点击Add按钮时,将检查字段是否为空,电子邮件格式和图像格式。验证消息应显示在tooltip。当所有验证都将成功的所有领域价值都可以收集和提交。请帮助我。

1 个答案:

答案 0 :(得分:0)

没有人会为您写任何验证。但是,您可以检查ppl已经创建的一些库,例如http://parsleyjs.org/处的 parsley 。它是Web表单的一个很好的验证器