javascript - 我无法让客户端和服务器端验证工作

标签 javascript php jquery

我有以下表格

<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>

您应该指定 php 的方法和名称文件在 <form> ,您的控件将继续 submit .

查看此http://www.w3schools.com/php/php_forms.asp

关于javascript - 我无法让客户端和服务器端验证工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38824227/

相关文章:

javascript - Webkit-playsinline 在 iphone 上

php - 将 php 嵌入到 C++ 应用程序中或以任何方式完成?

php - 正则表达式在字符串的特定位置添加连字符

php - "an established connection"什么时候应该在 CodeIgniter 中为真?

jquery - HTML5视频背景-IE错误

javascript - Ajax调用php未找到,404错误

javascript - Firefox 两次触发 css load 事件

Javascript 下载 URL - Azure Blob 存储

javascript - jQuery 中的 Canvas 对象,可能吗?

jquery - 如何在固定时间间隔后滑动文本