[英]html5 form validation in codeigniter view file
This is my simple html form code 这是我简单的html表单代码
<form method="post" action=<?php echo base_url()."index.php/controller_bookplot2";?>
name="frmbooking" id="frmbooking">
<div class="marginbtm5">
<select name="name_title" class="dropdown" id="name_title" required>
<option value="Mr.">Mr.</option>
<option value="Miss">Miss</option>
<option value="Mrs">Mrs</option>
<option value="Dr.">Dr.</option>
</select>
<img src=<?php echo base_url()."images/rightmarked.gif";?> title="mandetory">
</div>
<div class="marginbtm5">
<input name="name" type="text" class="input validate_B" id="name" onfocus="if (this.value
== 'Full Name') {this.value=''}" onblur="if(this.value == '') {
this.value='Full Name'}" value="Full Name" required>
<img src=<?php echo base_url()."images/rightmarked.gif";?> title=" mandetory">
</div>
<div class="marginbtm5">
<input name="address" type="text" class="input validate_B" id="add" onfocus="if
(this.value == 'Address') {this.value=''}" onblur="if(this.value ==
'') { this.value='Address'}" value="Address" required>
<img src=<?php echo base_url()."images/rightmarked.gif";?> title=" mandetory">
</div>
<div class="marginbtm5">
<input name="email" type="text" class="input validate_B" id="email" onfocus="if
(this.value == 'Email') {this.value=''}" onblur="if(this.value ==
'') { this.value='Email'}" required value="Email" >
<img src=<?php echo base_url()."images/rightmarked.gif";?> title=" mandetory"
style="display:none;">
</div>
<div class="marginbtm5">
<input name="dob" type="text" class="input" value="Birth Date" required id="datepicker" >
<img src=<?php echo base_url()."images/rightmarked.gif";?> title=" mandetory">
</div>
<div class="marginbtm5">
<input name="mobno" type="text" class="input validate_B" maxlength="45" onfocus="if
(this.value == 'Mobile (10 digit mobile no. eg 9812345678)')
{this.value=''}" onblur="if(this.value == '') { this.value='Mobile
(10 digit mobile no. eg 9812345678)'}" value="Mobile (10 digit mobile no. eg
9812345678)" id="mob_no" pattern="[789][0-9]{9}" required
onkeyup="javascript:ValidateText(this)" >
</div>
<input name="btnSubmit" type="image" src=<?php echo base_url()."images/submit.jpg";?> value="Submit" onclick="return validate();">
</form>
There are many other fields in my form. 我的表单中还有许多其他字段。 But I just put here 5 fields. 但是我只在这里放了5个字段。 When I click on submit, It directly displays html5 required message for mobile no field. 当我单击提交时,它将直接显示html5必填消息,用于移动电话号码字段。 It dont validate name,address,email,birthdate field first. 它不首先验证姓名,地址,电子邮件,生日字段。 So What Am I doing wrong?? 那么我在做什么错呢?
its not working because of you are giving the value attribute remove value attribute and try like this 它不起作用,因为您正在给value属性赋予remove value属性并尝试这样
<form method="post" action=<?php echo base_url()."index.php/controller_bookplot2";?>
name="frmbooking" id="frmbooking">
<div class="marginbtm5">
<select name="name_title" class="dropdown" id="name_title" required>
<option value="">--Please select type</option>
<option value="Mr.">Mr.</option>
<option value="Miss">Miss</option>
<option value="Mrs">Mrs</option>
<option value="Dr.">Dr.</option>
</select>
<img src=<?php echo base_url()."images/rightmarked.gif";?> title="mandetory">
</div>
<div class="marginbtm5">
<input name="name" type="text" class="input validate_B" id="name" onfocus="if (this.value
== 'Full Name') {this.value=''}" onblur="if(this.value == '') {
this.value='Full Name'}" Placeholder="Full Name" required>
<img src=<?php echo base_url()."images/rightmarked.gif";?> title=" mandetory">
</div>
<div class="marginbtm5">
<input name="address" type="text" class="input validate_B" id="add" onfocus="if
(this.value == 'Address') {this.value=''}" onblur="if(this.value ==
'') { this.value='Address'}" Placeholder="Address" required>
<img src=<?php echo base_url()."images/rightmarked.gif";?> title=" mandetory">
</div>
<div class="marginbtm5">
<input name="email" type="text" class="input validate_B" id="email" onfocus="if
(this.value == 'Email') {this.value=''}" onblur="if(this.value ==
'') { this.value='Email'}" required Placeholder="Email" >
<img src=<?php echo base_url()."images/rightmarked.gif";?> title=" mandetory"
style="display:none;">
</div>
<div class="marginbtm5">
<input name="dob" type="text" class="input" Placeholder="Birth Date" required id="datepicker" >
<img src=<?php echo base_url()."images/rightmarked.gif";?> title=" mandetory">
</div>
<div class="marginbtm5">
<input name="mobno" type="text" class="input validate_B" maxlength="45" onfocus="if
(this.value == 'Mobile (10 digit mobile no. eg 9812345678)')
{this.value=''}" onblur="if(this.value == '') { this.value='Mobile
(10 digit mobile no. eg 9812345678)'}" value="Mobile (10 digit mobile no. eg
9812345678)" id="mob_no" pattern="[789][0-9]{9}" required
onkeyup="javascript:ValidateText(this)" >
</div>
<input name="btnSubmit" type="image" src=<?php echo base_url()."images/submit.jpg";?> value="Submit" onclick="return validate();">
</form>
if you add value to input tag then it will not validate that filed because this filed having already value 如果您向输入标签添加值,那么它将不会验证该字段,因为该字段已具有值
No need to wirte onfocus="if (this.value == 'Full Name') {this.value=''}" onblur="if(this.value == '') { this.value='Full Name'}" value="Full Name"
无需输入onfocus="if (this.value == 'Full Name') {this.value=''}" onblur="if(this.value == '') { this.value='Full Name'}" value="Full Name"
this can be achieve by html attribute placeholder='Full Name'
这可以通过html属性placeholder='Full Name'
来实现
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.