The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other HTML form – make one of two fields required

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #37738

    I’m thinking about adding a contact form to my my art league’s website.

    It’ll have just five fields (TO, with the addressees selectable from a list; YOUR NAME, a text field without any pattern-matching validation; YOUR PHONE, also text with no pattern-matching validation; YOUR EMAIL, a text field probably with some validation to insure a valid email address syntax; and MESSAGE, a text field probably with a maximum character limit) plus, of course, a SEND button. Even though this will be my first form, I’ve read enough that I think I can handle the markup and CSS, so I’m not asking for help with that (at least not yet).

    But we’ll need to have either YOUR PHONE or YOUR EMAIL required – one of these, but not both.

    Some Google searching suggests that this is possible using scripting, or possibly if you’re using PHP. Unfortunately I am completely inexperienced with scripting and PHP, so those are not options for me.

    Is there a pure HTML/CSS way to accomplish this?



    “But we’ll need to have either YOUR PHONE or YOUR EMAIL required – one of these, but not both.”.

    People won’t understand that, if they see two fields they’ll automatically complete them especially as they are compulsory (in effect).

    If you need one of two, I’d give them an option to select their preferred choice and then reveal the necessary input.

    Alternatively, make them enter both but insist on a ‘preferred’ method…it’s just coming at it from the other direction.


    Thanks for the quick response – I appreciate it.

    Just to clarify:

    I was planning on having something (maybe an * with a note “* = required”) to indicate required fields, but got stuck on how to indicate that we’d like both but only 1 of the 2 was required.

    I wasn’t thinking of including the sentence “But we’ll need to have either YOUR PHONE or YOUR EMAIL required – one of these, but not both.” on the form., but maybe that’s the simplest way to go if I phrase it better.

    And maybe I’m wrong, but if I see a form with fields for my phone number and email address that are NOT required, I’ll usually leave them blank. I think that people are increasingly realizing that it’s not in their best interests to divulge this info (selling to telemarketers, opening the door to SPAM, etc.) unless it’s absolutely necessary.


    Thanks Chris.

    As I said, I have zero experience/knowledge of PHP or scripting, but I think I follow your example. Will try it later today.

    Meanwhile, is it true that there’s no way to do this (make it so that either of two fields is required) with just HTML & CSS?

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Other’ is closed to new topics and replies.