使用javascript和PHP对每个类元素进行验证,然后从“下一步”按钮中删除禁用的类
我试图对每个类元素进行验证。我使用的表单有多个输入,具有相同的名称属性。我想验证每个输入元素 这是我的HTML使用javascript和PHP对每个类元素进行验证,然后从“下一步”按钮中删除禁用的类,javascript,php,jquery,html,twitter-bootstrap,Javascript,Php,Jquery,Html,Twitter Bootstrap,我试图对每个类元素进行验证。我使用的表单有多个输入,具有相同的名称属性。我想验证每个输入元素 这是我的HTML <input type="text" class="date_of_birth" name="date[]" onkeyup="dateOfBirth('stepbirth')" /> <span class="stepbirthVal"></span> <input type="text" class="date_of_birth" n
<input type="text" class="date_of_birth" name="date[]" onkeyup="dateOfBirth('stepbirth')" />
<span class="stepbirthVal"></span>
<input type="text" class="date_of_birth" name="date[]" onkeyup="dateOfBirth('stepbirth')" />
<span class="stepbirthVal"></span>
<a href="javascript:;" id="stepbirth" class="btn disabled" onclick="kindKompas('stepbirth')">Next Step</a>
我希望你们能理解我的问题
提前感谢。您应该循环查看以逗号分隔的日期字符串列表,验证每个字符串。以下是解决方案的模型:
<?php
$fieldValue = "20/02/2000,03/05/2010";
$fieldName = "stepbirth";
//Validate the DOB
if ($fieldName == 'stepbirth')
{
$birthDateLen = strlen($fieldValue);
if ($birthDateLen > 9)
{
foreach (explode(",", $fieldValue) as $dateString) {
echo $dateString;
//Get Timestamp passed over
$dt = DateTime::createFromFormat('d/m/Y', $dateString);
//$userDate = $dt->getTimestamp();
//Get Date 1 Year from Today
$yearTime = date(strtotime('+10000 year'));
//Get last 4 characters of the Date for the Year
$year = substr($fieldValue, -4);
if ($year <= 1900)
{
echo '{"code":0,"message":""}';
}
else if ($userDate < $yearTime)
{
//If User's Date is Within 1 Year
echo '{"code":1,"message":""}';
}
else
{
echo '{"code":0,"message":"Fill date to 365 days from now.}';
}
}
}
}
//Get Parameters Passed From the JS Call to This Script
$fieldValue = $_GET["q"];
$fieldName = $_GET["q2"];
//Validate the DOB
if($fieldName == 'stepbirth')
{
$birthDateLen = strlen($fieldValue);
if($birthDateLen > 9)
{
if (checkBirthDate($fieldValue))
{
//
//Get last 4 characters of the Date for the Year
$year = substr($fieldValue, -4);
if($year > 1900)
{
//Get Timestamp passed over
$dt = DateTime::createFromFormat('d/m/Y', $fieldValue);
$userDate = $dt->getTimestamp();
//Get Date 1 Year from Today
$yearTime = date(strtotime('+10000 year'));
//If User's Date is Within 1 Year
if($userDate < $yearTime)
{
echo '{"code":1,"message":""}';
}
else
{
echo '{"code":0,"message":"Fill date to 365 days from now.}';
}
}
}
else
{
echo '{"code":0,"message":"Please fill valid date of birth."}';
}
}
else
{
echo '{"code":0,"message":""}';
}
}
<?php
$fieldValue = "20/02/2000,03/05/2010";
$fieldName = "stepbirth";
//Validate the DOB
if ($fieldName == 'stepbirth')
{
$birthDateLen = strlen($fieldValue);
if ($birthDateLen > 9)
{
foreach (explode(",", $fieldValue) as $dateString) {
echo $dateString;
//Get Timestamp passed over
$dt = DateTime::createFromFormat('d/m/Y', $dateString);
//$userDate = $dt->getTimestamp();
//Get Date 1 Year from Today
$yearTime = date(strtotime('+10000 year'));
//Get last 4 characters of the Date for the Year
$year = substr($fieldValue, -4);
if ($year <= 1900)
{
echo '{"code":0,"message":""}';
}
else if ($userDate < $yearTime)
{
//If User's Date is Within 1 Year
echo '{"code":1,"message":""}';
}
else
{
echo '{"code":0,"message":"Fill date to 365 days from now.}';
}
}
}
}