2014-11-08 52 views
0

我正在处理这个示例请求论坛,它与一个篮子一起工作,我通过调整表单来验证它,以便它使用HTML5验证,该工作适用于Dandy。但在此之前改变了“一个提交”按钮,“输入按钮”,它用来阻止表单提交,如果篮下利用这个曾在它超过5个项目:HTML5表单验证与JavaScript篮子验证相结合?

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

所以现在它验证形式,但会让你提交超过5个项目,我们不想要的,如果我将它改回锚链接,html5 fourm将无法正常工作,所以我需要一种方法来结合这两个。

这是该论坛作为一个整体:

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

我身边有一个公平的外观和没有运气到目前为止,如果任何人有任何建议,请给它们扔我的方式!谢谢! :)

回答

1

只需使用onclick属性的表单按钮,这将使我们的行为方式,你以前有链接一样:

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

这几乎如预期运作,它会导致JavaScript来显示“不超过5个样本”格,但形式仍然运行,虽然感谢!至少我已经过了第一个障碍! – 2014-11-08 21:35:53

+0

如果检查失败,尝试在closeFiveCheck函数中返回false – Maxime 2014-11-08 21:37:12

+0

修复它!非常感谢你! = d !! – 2014-11-08 21:42:28