Php 提交前的表单验证
我有以下表单需要输入数据库,但我希望在将其保存到数据库之前对其进行验证:Php 提交前的表单验证,php,jquery,forms,validation,codeigniter-2,Php,Jquery,Forms,Validation,Codeigniter 2,我有以下表单需要输入数据库,但我希望在将其保存到数据库之前对其进行验证: <form name="add_walkin_patient_form" class="add_walkin_patient_form" id="add_walkin_patient_form" autocomplete="off" > <div class="form-line"> <div class="cont
<form name="add_walkin_patient_form" class="add_walkin_patient_form" id="add_walkin_patient_form" autocomplete="off" >
<div class="form-line">
<div class="control-group">
<label class="control-label">
Patient Name
</label>
<div class="controls">
<input type="text" name="patientname" id="patientname" required="" value=""/>
</div>
</div>
<div class="control-group">
<label class="control-label">
Patient Phone Number
</label>
<div class="controls">
<input type="text" name="patient_phone" id="patient_phone" required="" value=""/>
</div>
</div>
<div class="control-group">
<label class="control-label">
Department
</label>
<div class="controls">
<select name="department" required="" class="department" id="department">
<option value="">Please select : </option>
<option value="Pharmacy">Pharmacy</option>
<option value="Laboratory">Laboratory</option>
<option value="Nurse">Nurse</option>
</select>
</div>
</div>
</div>
<button name="add_walkin_patient_button" type="submit" id="add_walkin_patient_button" class="btn add_walkin_patient_button btn-info pull-right">
Add Walk In Patient
</button>
</form>
患者姓名
病人电话号码
部门
请选择:
药店
门诊化验室
看护
添加步入式患者
提交由jquery脚本使用以下脚本完成:
<script type="text/javascript">
$(document).ready(function () {
//delegated submit handlers for the forms inside the table
$('#add_walkin_patient_button').on('click', function (e) {
e.preventDefault();
//read the form data ans submit it to someurl
$.post('<?php echo base_url() ?>index.php/reception/add_walkin', $('#add_walkin_patient_form').serialize(), function () {
//success do something
// $.notify("New Patient Added Succesfully", "success",{ position:"left" });
$(".add_walkin_patient_form").notify(
"New Walkin Patient Added Successfully",
"success",
{position: "center"}
);
setInterval(function () {
var url = "<?php echo base_url() ?>index.php/reception/";
$(location).attr('href', url);
}, 3000);
}).fail(function () {
//error do something
$(".add_walkin_patient_form").notify(
"There was an error please try again later or contact the system support desk for assistance",
"error",
{position: "center"}
);
})
})
});
</script>
$(文档).ready(函数(){
//表内表单的委托提交处理程序
$(“#添加_walkin_patient_按钮”)。在('click',函数(e){
e、 预防默认值();
//读取表单数据并将其提交到someurl
$.post('index.php/receipt/add_walkin',$('add_walkin_patient_form')。serialize(),function(){
//成功做点什么
//$.notify(“新患者添加成功”,“成功”,“位置:{left}”);
$(“.add_walkin_patient_form”)。通知(
“已成功添加新的Walkin患者”,
“成功”,
{位置:“中心”}
);
setInterval(函数(){
var url=“index.php/receivement/”;
$(location.attr('href',url);
}, 3000);
}).fail(函数(){
//做某事
$(“.add_walkin_patient_form”)。通知(
“出现错误,请稍后再试或联系系统支持台寻求帮助”,
“错误”,
{位置:“中心”}
);
})
})
});
在将输入提交到脚本之前,如何进行表单验证以检查输入是否为空 您正在使用
<button name="add_walkin_patient_button" type="submit" id="add_walkin_patient_button" class="btn add_walkin_patient_button btn-info pull-right">
Add Walk In Patient
</button>
如果您使用的是normal
按钮,而不是submit
按钮,则此功能会起作用
<input type="button">Submit</button>
附言
我建议您按照您正在使用的建议使用
<button name="add_walkin_patient_button" type="submit" id="add_walkin_patient_button" class="btn add_walkin_patient_button btn-info pull-right">
Add Walk In Patient
</button>
如果您使用的是normal
按钮,而不是submit
按钮,则此功能会起作用
<input type="button">Submit</button>
附言
我建议您按照您正在使用的建议使用
<button name="add_walkin_patient_button" type="submit" id="add_walkin_patient_button" class="btn add_walkin_patient_button btn-info pull-right">
Add Walk In Patient
</button>
如果您使用的是normal
按钮,而不是submit
按钮,则此功能会起作用
<input type="button">Submit</button>
附言
我建议您按照您正在使用的建议使用
<button name="add_walkin_patient_button" type="submit" id="add_walkin_patient_button" class="btn add_walkin_patient_button btn-info pull-right">
Add Walk In Patient
</button>
如果您使用的是normal
按钮,而不是submit
按钮,则此功能会起作用
<input type="button">Submit</button>
附言
我建议您按照的建议使用javascript验证方法(例如,validateForm(),使用bool返回类型)。在表单中添加[onsubmit=“return validateForm()”]属性,就完成了。创建一个javascript验证方法(例如,validateForm(),使用bool返回类型)。在表单中添加[onsubmit=“return validateForm()”]属性,就完成了。创建一个javascript验证方法(例如,validateForm(),使用bool返回类型)。在表单中添加[onsubmit=“return validateForm()”]属性,就完成了。创建一个javascript验证方法(例如,validateForm(),使用bool返回类型)。将[onsubmit=“return validateForm()”]属性添加到表单中,就完成了。您需要防止默认操作
$('#add_walkin_patient_form').on('submit', function(e) {
e.preventDefault();
//Validate form and submit
});
您需要防止默认操作
$('#add_walkin_patient_form').on('submit', function(e) {
e.preventDefault();
//Validate form and submit
});
您需要防止默认操作
$('#add_walkin_patient_form').on('submit', function(e) {
e.preventDefault();
//Validate form and submit
});
您需要防止默认操作
$('#add_walkin_patient_form').on('submit', function(e) {
e.preventDefault();
//Validate form and submit
});
我正在使用javascript进行验证。 以下为表格编号:
<form action="upload.php" method="post" onSubmit="return validateForm()">
<input type="text" id="username">
<input type="text" password="password">
<input type="submit" value='Login' name='login'>
</form>
要执行验证,请编写javascript函数:
<script>
function checkform(){
var uname= document.getElementById("username").value.trim().toUpperCase();
if(uname=== '' || uname=== null) {
alert("Username is blank");
document.getElementById("username").backgroundColor = "#ff6666";
return false;
}else document.getElementById("username").backgroundColor = "white";
var pass= document.getElementById("password").value.trim().toUpperCase();
if(pass=== '' || pass=== null) {
alert("Password is blank");
document.getElementById("password").backgroundColor = "#ff6666";
return false;
}else document.getElementById("password").backgroundColor = "white";
return true;
}
</script>
函数检查表(){
var uname=document.getElementById(“用户名”).value.trim().toUpperCase();
如果(uname==''| | uname===null){
警报(“用户名为空”);
document.getElementById(“用户名”).backgroundColor=“#ff6666”;
返回false;
}else document.getElementById(“用户名”).backgroundColor=“白色”;
var pass=document.getElementById(“密码”).value.trim().toUpperCase();
如果(通过==''| |通过===null){
警报(“密码为空”);
document.getElementById(“密码”).backgroundColor=“#ff6666”;
返回false;
}else document.getElementById(“密码”).backgroundColor=“白色”;
返回true;
}
我正在使用javascript进行验证。
以下为表格编号:
<form action="upload.php" method="post" onSubmit="return validateForm()">
<input type="text" id="username">
<input type="text" password="password">
<input type="submit" value='Login' name='login'>
</form>
要执行验证,请编写javascript函数:
<script>
function checkform(){
var uname= document.getElementById("username").value.trim().toUpperCase();
if(uname=== '' || uname=== null) {
alert("Username is blank");
document.getElementById("username").backgroundColor = "#ff6666";
return false;
}else document.getElementById("username").backgroundColor = "white";
var pass= document.getElementById("password").value.trim().toUpperCase();
if(pass=== '' || pass=== null) {
alert("Password is blank");
document.getElementById("password").backgroundColor = "#ff6666";
return false;
}else document.getElementById("password").backgroundColor = "white";
return true;
}
</script>
函数检查表(){
var uname=document.getElementById(“用户名”).value.trim().toUpperCase();
如果(uname==''| | uname===null){
警报(“用户名为空”);
document.getElementById(“用户名”).backgroundColor=“#ff6666”;
返回false;
}else document.getElementById(“用户名”).backgroundColor=“白色”;
var pass=document.getElementById(“密码”).value.trim().toUpperCase();
如果(通过==''| |通过===null){
警报(“密码为空”);
document.getElementById(“密码”).backgroundColor=“#ff6666”;
返回false;
}else document.getElementById(“密码”).backgroundColor=“白色”;
返回true;
}