javascript - Is there a way for a form to identify only one required field -
for instance in example;
<form> <input type="email" name="email" id="useremail" placeholder="email address" required> <br> <input type="tel" name="phone" id="userphone" placeholder="phone number" maxlength="10" required> <br> <input type="submit" id="sidebarformsubmit" value="submit"> </form>
is possible somehow/somewhere able identify user has inputed in either email or phone number field. on submit doesn't show "this required".
reword: can @ least 1 of form inputs mandatory, both allowed 1 or other not none. in above example, user needs have @ least 1 form of communication whether phone number or email. can have both however, not none.
if so, how go this?
is possible somehow/somewhere able identify user has inputed in either email or phone number field. on submit doesn't show "this required".
1) no. if use html5 required
on field that field required. there no way specify interdependence.
2) yes. can use client-side javascript validation, hooked form submit
event as-complex-as-you-like validation. prevent submit returning false
event handler if don't pass validation.
3) yes. can validation can complex necessary on server when have received submitted form, , return directly form if wrong.
3b) must validation on server, if have great client-side javascript validation, otherwise buy things site 1 penny. must not trust client.
Comments
Post a Comment