WordPress.org

Ready to get started?Download WordPress

Forums

Checking form fields for Null entry? (3 posts)

  1. LesTexas60
    Member
    Posted 6 months ago #

    I am trying to set some required fields in a PDF file that I will embed in a page. I have the code below:

    event.rc = true;
    if (event.value == " " || event.value ==null )
    {
    app.alert("This is a REQUIRED FIELD'!");
    event.rc = false;
    }

    If a space is entered it returns the error.
    If the field is just returned through it does not report the error.
    what am I missing in my code?
    Thanks

  2. bcworkz
    Member
    Posted 6 months ago #

    Hmm, I haven't seriously worked with javascript in a while. IIRC, to check for an ignored field you check for an empty string: event.value == "". So now you've checked for ignored field and an empty space. What if there are two spaces? A dot? It's hard to anticipate what someone may do.

    You may be better off using a regexp to check for a match to what is right instead of trying to anticipate what is wrong. Just a thought, it depends on how important the field is. I've found checking for an empty string suffices for client side script. If more rigorous checking is required, it should be done server side. Javascript is inherently insecure.

  3. LesTexas60
    Member
    Posted 6 months ago #

    bc,you bring up some good points. I'm just trying to reenforce that a few fields are entered, such as Name, Phoone No, etc. There is no real validation because they could enter anything. The point is to make sure they just don't skip over it and leave it blank. When they walk in the door and it say Dog I can than ask them why they tried to skip a field that was tagged as required.

    THanks

Reply

You must log in to post.

About this Topic

Tags

No tags yet.