我正在处理一个表格,其中我有2个输入,其中包含2个日期输入,主要是出发日期和返回日期。我正在使用欧芹javascript进行验证。在创建自定义Js验证规则以比较两个字段并检查出发日期是今天之后的日期,而返回日期应该是出发日期之后的3天或更长时间时,我需要帮助
表单上的输入
<?php
if(!isset($_SESSION))
{
session_start();
}
ob_start();
include('template.php');
require('config/config.php');
if(isset($_SESSION['user']))
{
$currentTime = time();
if($currentTime < $_SESSION['expire'])
{
?>
<html>
<head>
<meta charset="utf-8">
<title>Home</title>
</head>
<body>
<div class="container header">
<div id="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href=""><img id="imgNavbar" src="../img/candidacy.jpg" alt="Home"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="../index.php">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo $_SESSION['user']['nameUser']?></a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="myProfile.php">My Profile</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="listCandidacies.php">List of candidacies</a>
</li>
<li class="nav-item">
<a class="nav-link" href="addCandidacy.php">Add a candidacy</a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">Disconnect</a>
</li>
</ul>
</div>
</nav>
</div>
<div class="content">
<div class="col-lg-10">
<h3 class="text-uppercase">
<strong>Welcome to candidacy <br>space !</strong>
</h3>
</div>
</div>
<?php
}
else
{
unset($_SESSION['user']);
session_destroy();
header('Location: ../login.php');
}
}
else
{
unset($_SESSION['user']);
session_destroy();
header('Location: ../login.php');
}
?>
自定义欧芹Js代码
<!-- Departure date-->
<div class="form-line registar2 love {{ $errors->has('departure_date') ? ' has-error' : '' }}">
<input type="date" class="form-input" name="departure_date" value="{{ old('departure_date') }}" required data-parsley-depart= ''>
<label>Departure Date *</label>
<div class="error-label">Field is required!</div>
<div class="check-label"></div>
@if ($errors->has('departure_date'))
<span class="help-block">
<strong>{{ $errors->first('departure_date') }}</strong>
</span>
@endif
</div>
<!--End departure-->
<!-- Return date-->
<div class="form-line registar2 move {{ $errors->has('return_date') ? ' has-error' : '' }}">
<input type="date" class="form-input" name="return_date" value="{{ old('return_date') }}" required data-parsley-return= ''>
<label>Return Date *</label>
<div class="error-label">Field is required!</div>
<div class="check-label"></div>
@if ($errors->has('return_date'))
<span class="help-block">
<strong>{{ $errors->first('return_date') }}</strong>
</span>
@endif
</div>
<!-- End return date-->
答案 0 :(得分:0)
处理依赖项有些棘手。您可以执行类似in this example的操作,也可以向一个输入添加验证器,并在另一个输入接收到'input'
事件时在那里触发'input'
事件。