dongwenghe2416
dongwenghe2416
2011-08-26 13:02

如何验证提交的表单是否为空?

  • input
  • validation
  • php
已采纳

My form consists of different types of inputs.

Is there a way of checking if form has been submitted with any user input?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • dty63504 dty63504 10年前

    Is there a way of checking if an entire form is blank?

    Without checking each individual input?

    In short. No there is not.

    You could treat $_POST as an array and check each entry in a loop, but you must be aware of items that are automatically filled, like $_POST['submit'] or something similar.

    点赞 评论 复制链接分享
  • douhao2721 douhao2721 10年前

    To see if anything is present (either a text input, or at least a checkbox value=1) you might use:

    strlen(join($_POST))
    

    Obviously only if it's a POST form, and that's not a big help either if you have radio or select boxes with a default. Also the submit button may not add a string by itself (don't give it a name=).

    点赞 评论 复制链接分享
  • dousuochu7291 dousuochu7291 10年前

    Run the input through array_filter - it will return empty array if there is no single value in the array. If there is a value, the array will be non-empty.

    Keep in mind that this way even if just one checkbox is checked form will be considered non-empty.

    点赞 评论 复制链接分享

为你推荐