简体   繁体   English

HTML5表单验证与javascript篮子验证相结合?

[英]HTML5 Form validation with javascript basket validation combined?

I'm working on this sample request forum which works with a basket, I've validated it by tweaking the form so that it uses HTML5 validation, that works dandy. 我正在与篮子一起使用的这个示例请求论坛上进行工作,我已经通过调整表单进行了验证,以便它使用HTML5验证,而且非常有用。 But prior to changing the "a submit" button to an "input button", it used to stop the form submission if the basket had more than 5 items in it by using this: 但是在将“提交”按钮更改为“输入按钮”之前,如果购物篮中包含超过5个项目,它会使用以下方法停止提交表单:

<a href="javascript:closeFiveCheck();"> BUTTON </a>

So now it validates the form but will let you submit the request with more than 5 items, which we don't want, and if i change it back to the anchor link, the html5 fourm won't work, so I need a way to combine the two. 因此,现在它可以验证表单,但可以让您提交超过5个项目的请求,这是我们不想要的,如果我将其更改回锚链接,则html5 fourm将无法工作,因此我需要一种方法结合两者。

Here is the forum as a whole: 这里是整个论坛:

echo '<form name="SEARCH" id="SEARCH" method="POST" action="orderSamples.php" enctype="multipart/form-data">';
echo '<div class="mainBasketContact">';
echo '<a href="design-search.php"><img src="images/basketLong.png" /></a>';
echo '<p>Enter your details to receive your free samples. Please allow 7 working days for delivery.</p>';
echo '<div class="contactLabel">NAME</div><div class="contactLabel2"><input required="required" style="background:#'.$basketColour.';" type="text" name="NAME" id="NAME" /></div><div style="clear: both;"></div>';
echo '<div class="contactLabel">COMPANY</div><div class="contactLabel2"><input style="background:#'.$basketColour.';" type="text" name="COMPANY" id="COMPANY" /></div><div style="clear: both;"></div>';
echo '<div class="contactLabel">EMAIL</div><div class="contactLabel2"><input required="required" type="email" style="background:#'.$basketColour.';" name="EMAIL" id="EMAIL" /></div><div style="clear: both;"></div>';
echo '<div class="contactLabel">TEL</div><div class="contactLabel2"><input type="number" required style="background:#'.$basketColour.';" name="TEL" id="TEL" /></div><div style="clear: both;"></div>';
echo '<div class="contactLabel">PROJECT TITLE</div><div class="contactLabel2"><input style="background:#'.$basketColour.';" type="text" name="PROJECT" id="PROJECT" /></div><div style="clear: both;"></div>';
//echo '<div class="contactLabel">ADDRESS</div><div class="contactLabel2"><textarea style="background:#'.$basketColour.';" name="ADDRESS" id="ADDRESS" /></textarea></div><div style="clear: both;"></div>';

echo '<p class="dcHeader1">DELIVERY ADDRESS</p>';
echo '<div class="contactLabel">LINE 1</div><div class="contactLabel2"><input required="required" type="text" style="background:#'.$basketColour.';" name="AD1" id="AD1" /></div><div style="clear: both;"></div>';
echo '<div class="contactLabel">LINE 2</div><div class="contactLabel2"><input type="text" style="background:#'.$basketColour.';" name="AD2" id="AD2" /></div><div style="clear: both;"></div>';
echo '<div class="contactLabel">TOWN/CITY</div><div class="contactLabel2"><input required="required" type="text" style="background:#'.$basketColour.';" name="TOWN" id="TOWN" /></div><div style="clear: both;"></div>';
echo '<div class="contactLabel">POSTCODE</div><div class="contactLabel2"><input required="required" type="text" style="background:#'.$basketColour.';" name="POSTCODE" id="POSTCODE" /></div><div style="clear: both;"></div>';
echo '<div class="contactLabel">FURTHER<br/>NOTES</div><div class="contactLabel2"><textarea name="MESSAGE" id="MESSAGE" style="background:#'.$basketColour.';"></textarea></div><div style="clear: both;"></div>';

echo '<input type="submit" name="Submit" value="SUBMIT" />';
echo '</div>';
echo '<div style="clear: both;"></div>';
echo '</div>';
echo '</form>';

I've had a fair look around and had no luck so far, if anyone has ANY suggestions please throw them my way! 我环顾四周,到目前为止还没有运气,如果有人有任何建议,请把它们扔给我! Thankyou! 谢谢! :) :)

只需在表单按钮上使用onclick属性,即可使其行为与之前的链接相同:

<input type="submit" name="Submit" value="SUBMIT" onclick="return closeFiveCheck();" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM