我创建了以下表单。 它接受数据,正确地在数据库中输入。 但它也接受空白输入。 我已经完成了以下代码来执行验证,但它无法正常工作。
<form novalidate="" name="storeForm" action="book.php" onsubmit="book.php"
method="POST">
<div class="storeInputContainer">
<input class="storeInput" placeholder="Name *" name="Name" type="text"
required>
</div>
<div class="storeInputContainer">
<input class="storeInput" placeholder="Phone Number *" name="Number"
type="phone" required>
</div>
<div class="lineBreak">
<br>
</div>
<div class="storeInputContainer">
<input class="storeInput" placeholder="Address *" name="Address"
type="text" required>
</div>
<div class="storeInputContainer">
<select name="Postcode" value="" placeholder="Post Code/Area"
class="storeInput" required onchange="myNewfunction(this);">
<option value="411002">411002 (Pune City H.O.)</option>
<option value="411004">411004 (Deccan Gymkhana)</option>
<option value="411005">411005 (Shivajinagar H.O.)</option>
<option value="411006">411006 (Yerawada)</option>
<option value="411007">411007 (Ganeshkhind)</option>
<option value="411008">411008 (N.C.L.)</option>
<option value="411009">411009 (Parvati)</option>
<option value="411010">411010 (S.S.C. Board)</option>
<option value="411011">411011 (Kasba Peth)</option>
<option value="411012">411012 (Dapodi)</option>
<option value="411013">411013 (Hadapsar)</option>
<option value="411014">411014 (Dunkirk Line)</option>
<option value="411015">411015 (Dighi Camp)</option>
<option value="411016">411016 (Model Colony)</option>
<option value="411017">411017 (Pimpri Colony)</option>
<option value="411018">411018 (Pimpri Penicillin Factory)</option>
<option value="411019">411019 (Chinchwad East)</option>
<option value="411020">411020 (Khadaki/Range Hill)</option>
<option value="411021">411021 (Armament )</option>
<option value="411022">411022 (S.R.P.F.)</option>
<option value="411023">411023 (N.D.A.)</option>
<option value="411024">411024 (Khadakwasala)</option>
<option value="411025">411025 (I.A.T. Pune)</option>
<option value="411026">411026 (Bhosari Indus.estate)</option>
<option value="411027">411027 (Aundh Camp)</option>
<option value="411028">411028 (Hadapsar_)</option>
<option value="411030">411030 (S.P. College)</option>
<option value="411031">411031 (C.M.E.)</option>
<option value="411032">411032 (I.A.F. station)</option>
<option value="411033">411033 (Chinchwad Gaon)</option>
<option value="411034">411034 (Kasarwadi)</option>
<option value="411035">411035 (Akurdi)</option>
<option value="411036">411036 (Mundhwa)</option>
<option value="411037">411037 (Market Yard)</option>
<option value="411038">411038 (Kothrud/Ex. Service man colony)</option>
<option value="411039">411039 (Bhosari Gaon)</option>
<option value="411040">411040 (Wanawadi)</option>
<option value="411041">411041 (Wadgaon Budruk)</option>
<option value="411042">411042 (Swargate)</option>
<option value="411043">411043 (Dhankawadi)</option>
<option value="411044">411044 (Pimpri Chinchwad)</option>
<option value="411045">411045 (Pashan)</option>
<option value="411046">411046 (Katraj)</option>
<option value="411047">411047 (Lohgaon)</option>
<option value="411048">411048 (N.I.B.M.)</option>
<option value="411051">411051 (Anandnagar)</option>
<option value="411052">411052 (Navasahyadri/Warje Malwadi)</option>
<option value="411053">411053 (Shivaji Hsg Society)</option>
</select>
</div>
<div class="extraLarge"></div>
<div class="callBack">
<button type="submit" class="callBackBtn"> Call me Back</button>
</div>
</form>
请帮我解决这个问题。 在此先感谢
答案 0 :(得分:0)
HTML5&#39;要求&#39;标签本身没有足够的验证。并非所有浏览器都支持它们,旧版浏览器会忽略它们。在将任何表单数据写入数据库之前,您仍需要使用PHP处理表单提交。
novalidate=""
和onsubmit="book.php"
也不会按照您的意愿行事。
答案 1 :(得分:0)
尝试将Js文件用于验证表单。您需要使用HTML5进行客户端验证。