我正在开发这个与购物篮一起使用的示例请求论坛,我通过调整表单以使其使用 HTML5 验证来验证它,效果非常好。但在将“提交”按钮更改为“输入按钮”之前,如果购物篮中的元素超过 5 个,它会使用以下方法停止表单提交:
<a href="javascript:closeFiveCheck();"> BUTTON </a>
现在它会验证表单,但会让您提交包含超过 5 个项目的请求,这是我们不想要的,如果我将其改回 anchor 链接,html5 论坛将无法工作,所以我需要一种将两者结合起来的方法。
这是整个论坛:
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>';
我已经仔细观察过,到目前为止还没有运气,如果有人有任何建议,请告诉我!谢谢你! :)
最佳答案
只需在表单按钮上使用 onclick 属性,这应该使其行为方式与您之前的链接相同:
<input type="submit" name="Submit" value="SUBMIT" onclick="return closeFiveCheck();" />
关于javascript - HTML5 表单验证与 javascript 篮子验证相结合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26821105/