我无法让客户端和服务器端验证工作
I cannot get client side and server side validation to work
我有以下形式的
<form name="courses">
<div="requiredfield">
<input type="text" name="coursename" id="coursename">
</div>
<input type="submit" name="submitform1">
</form>
<form name="students">
<div="requiredfield">
<input type="text" name="studentfirstname" id="studentfirstname">
</div>
<div="requiredfield">
<input type="text" name="studentlastname" id="studentlastname">
</div>
<div="requiredfield">
<input type="text" name="studentage" id="studentage">
</div>
<input type="submit" name="submitform2">
</form>
我使用此代码进行客户端验证
// this works fine
$('#courses').submit(e) {
e.preventDefault();
if ($('#coursename').val() == 0) {
// error message is appended to the div containing the field
// the same for the other form and its field
}
}
不起作用的是服务器端验证
<?php
if (isset($_POST['submitform1'])) {
if (empty($_POST['coursename'])) {
$course_mistake = "please fill this field"
}
}
?>
我不知道为什么服务器端验证不起作用。请帮帮我。
<form name = "courses" method="post" action="validation.php">
// Your form fields.
</form>
您应该在<form>
中指定php
文件的方法和名称,其中控件将在submit
上运行。
看看这个http://www.w3schools.com/php/php_forms.asp
1您阻止表单提交:
$('#courses').submit(e) {
e.preventDefault(); // This prevents form submitting to PHP side
如果你不使用Ajax(我看不到任何相关的代码(,那么你就要注意将数据发送到PHP
2<form name="courses">
表示您使用的是$_GET
方法,但在PHP中您需要$_POST
添加method="post"
或在PHP中使用$_GET
/$_REQUEST
。
3您不会在任何地方输出错误-缺少$course_mistake
处理
相关文章:
- 在Javascript中复制C#服务器端验证
- 表单的服务器端验证
- 用于显示服务器端验证结果的 Jqgrid 编辑事件
- 如何使用angular js在表单上显示服务器端验证错误消息
- Java服务器端验证
- 当需要服务器端验证时
- PHP 使用客户端和服务器端验证,而无需使用第三方代码
- 使用 JQuery 执行服务器端验证,然后将用户发送到另一个站点
- 主干:部分客户端验证 + 服务器端验证
- DropZone.js服务器端验证
- 服务器端验证,不关闭 JQuery(引导)对话框
- Asp.net.服务器端验证和客户端验证很好地协同工作的最佳方式是什么?
- Regex未在服务器端验证的代码隐藏中工作
- 使用socket.io进行服务器端验证
- 异步请求如何用于服务器端验证
- 我在PHP中的服务器端验证是在页面加载时进行的
- 客户端和服务器端验证
- angular服务器端验证,如何从对象引用中找到表单元素
- 在服务器端验证javascript代码
- 更改时删除服务器端验证格式更改