1,399 thoughts on “Zebra_Form, a jQuery augmented PHP library for creating and validating HTML forms

  1. Olivier Rochefort

    Just noted a bug when using latin characters and the autofill() function. Let’s say that I limit to 5 the number of characters that can be contained in a text field :

    $obj = $form->add('text', 'my_secret_code');
      'length'   => array(1, 5, 'error', 'Code too long'),

    Now, if I autofills the field with the text “é1234”, the text contained in the field will get truncated to “é123”. My guess is that the “é” character is stocked on two bytes and that you get a string length by counting the number of bytes.

    $form->auto_fill(array('my_secret_code' => 'é1234'))
  2. Matt

    Hi Stefan, I am using the Zebra_Form library in a project I am working on and have come up with a fairly unique obstacle, that I am hoping you might be able to help with. We are integrating with a payment gateway, and to avoid us having to be PCI DSS compliant, they recommend using their javascript API to intercept form data on submission, which generates and returns a token to identify the credit card on their system. The form is then submitted with the token instead of the actual credit card details. To do this, you do not name your input fields on the form, instead using a custom identifier that the JS can access, as unnamed form elements are not sent to the server. I have tested everything and it all works, however your library requires the inputs to be named, for obvious reasons. Is there an economical way to use the library with unnamed fields? Or am I better trying to replicate the look/feel/validation of your forms for the payment form? Or is there a 100% surefire way to prevent fields in a zebra form from being sent to the server?

    Any help would be great.

  3. Sander

    Within HTML5 it’s possible to use “number” for an input field.
    But I can’t find it within the Zebra Form. Only method is to choose “text” and than set a rule for “number”. That’s good but all users with a smartphone need to select the other numeric keyboard. If the input field was of the type “number” the smartphone would have done this automatically.

    Am I just not looking good enough? Or is this option not embedded?

    Regards, Sander

    1. Stefan Gabos Post author

      This is now fixed – elements having the “number”, “digits” or “float” rules set will have their type automatically changed to “number”. Thanks!

  4. Johan Smyth

    I’m using zebra forms and zebra database to manage my user registration and login forms.
    I’m struggling to verify the password provided at login against the hash stored in the database. I’m using php’s password_verify function with BCRYPT encryption algorithm.
    Does anyone have any advice on how to get the password to verify?

  5. Shabeer


    Its really a great plugin. I have been using this for more than years.

    Now i need a function where i want to know whether the form is valid or not without showing error message. Currently i am using


    but this will show the error message. I need the same function but i don’t need to show the error messages. Is there any option for that ?

    Also if there is any search for your comments it will be really great.

    Once again thanks a lot for this beautiful plugin.

    1. Stefan Gabos Post author

      You can now pass “false” as argument to the “validate” method



  6. Natalie

    I just got tripped up using a $ character in a label and having it denoting an accesskey instead of a literal $ character
    I read the documentation which said to escape the $ character with a backslash. I tried that and it still didn’t work.
    Then I realised it will only work if your label text is surrounded by double quotes. It won’t work if your label text is surrounded by single quotes which is what I had (and what is on your demo page)
    Just posting here in case it helps someone else.

    1. Natalie

      oops – sorry no that doesn’t work either
      I had to put the $ symbol in as a html code: & # 3 6 ;
      (I’ve put spaces in the code in case the form converts it to a $

  7. Jaco Roux

    Thanks for an excellent library.

    I have an issue with the dependencies rule when using multiple conditions.

    For example:

        'dependencies' => array(
                  "input1" => "value 1",
                  "input2" => array("value1","value2"),
                  "radio1" => array("1","2"),
        'mycallback, 1',

    I want it to work as a AND so all 3 conditions should be tested before the callback will fire, but it doesn’t want to work.

    It only tests the last one in the array in this example it will only test the radio1 value. If I remove the radio1 it only tests input2 and ignores input1.

    Please advise

    1. Stefan Gabos Post author

      This is now fixed – thanks for reporting! There will be a proper release later this week, with some more updates, but until then simply download the master release (instead of the 2.9.6 release)

    2. Jaco Roux

      Thanks it works now but there is still one issue.

      It checks all the conditions now and only executes the callback function if all conditions are true but if you change input1 or input2’s value it doesn’t do the callback, only the last condition is checked again if any of the values changed.

    3. Stefan Gabos Post author

      That is correct – the callback fires *only* if *all* conditions are met

    4. Jaco Roux

      I understand yes but what I need is for when the callback fired after all the conditions are true.

      I need it to fire again to hide the dependent element if I change any value in input1, inpu2 or radio1 but now it only does it when you change radio1.

    1. Stefan Gabos Post author

      this one was huge and it’s very lucky you’ve found it! actually, setting the “email” rule, or a numeric validation rule, resulted in those elements not being checked server-side! thanks a lot for reporting these bugs. you can download the fixed version from GitHub (the master branch, that is). Thanks a lot, again!

    2. Natalie

      Thanks for the quick fix. I downloaded the latest version of Zebra_Form.php but it doesn’t seem to fix the problem. It still blanks out the email and number values and now I can’t submit the form even when the captcha is correct as it says the phone field is not entered (the phone field has digits validation).

  8. Richard

    Heya, been using Zebra form for a small project, I decided to use hidden fields in place of cookies for my form processing.

    The thing is, when I use a field of type ‘hidden’, nothing gets passed to the $_POST, without it, everything works fine and I see every form item.. what am I missing here?


    1. Richard

      oh and another thing, the file upload field, once an item is chosen, it seems to slide in the background, as if the positioning changes to slide with the background on page scroll ({file name} X)

    2. Richard

      Please disregard my query, it seems all hidden fields (hidden, and apparently file uploads as well) appear at the very start of the $_POST, where I was expecting form names in my processing calls

      Thanks, Great work!

  9. Charlie

    This is a great package! I support a small non-profit organization and zebra_form has made my life much easier.

    Unfortunately I have hit a snag when trying to use the custom feature of “set_rule”. The callback function works, but if it returns “false” the error message is not displayed in a balloon attached to the given field, but at the top of the form. This behavior then also applies to all subsequently defined fields in the form, making it sometimes difficult to know which field entry is in error.

    As a simple test I used one of the examples distributed with the package and pasted in the example code (validation-vertical.php) for set_rule/custom from the documentation. The error code behavior is as I described above. Am I missing something obvious?

    Thank you for any help you can offer!

    1. Charlie

      As it turns out, I had a subtle syntax error in my code — not a PHP error but in my Zebra_Form coding. My simple test code works now, so I’ll continue working on my more complex custom validation. My apologies for what I think was a false alarm.

  10. sarath

    Whenever i set form option “action ” to some page the captcha validation is not working.but when i use ajax it works.How to solve it.

    1. sarath

      form validation is not working for me

  11. Grüne Leuchte

    Hi Stefan,
    Zebra_Form seems to meet my requirements. Can it be combined with Bootstrap?
    Best regards

    1. Stefan Gabos Post author

      Sure it can. You’ll just have to add the “form-control” class to every element (except labels, radio buttons and checkboxes) like

      $obj = $form->add('text', 'some_element', '', array('class' => 'form-control'));
  12. Tony

    Firstly, my sincere thanks for the effort that has gone into developing and documenting these excellent processes. I am using both Forms and Database.

    In Forms render(): The third method of rendering the output is through a callback function. This function/method will be auto generated by my process within its class. I was unable to find a way to get render() to natively call a method in a class.

    To resolve this, I have modified the render method to add an optional $class argument. If $class is not empty, I use array($class,$template) to check if(is_callable(… and call_user_func_array(….

    This may not be the optimal way to do this and any feedback would be appreciated.

  13. Jaco Roux

    I am experiencing an issue with the date picker when I try to call a js function onChange or onClose etc. The only two events that work are onBlur and onFocus. The onBlur works fine for the most part but when you change the calendar to the year view and click a new date it sees it as a blur and then the function fires.

    The ideal way for this function will be to call it on the onChange event.

    ‘required’ => array(‘error’,$translation->getValue(“errRequired”)),
    ‘date’ => array(‘error’,$translation->getValue(“errDate”)),
    ‘style’ => ‘width:50%’,
    ‘onBlur’ => ‘enableDae()’,
    ‘onChange’ => ‘jaarDatumToets()’, //DOES NOT WORK
    ‘onFocus’ => ‘clearDae()’,

  14. ceskmm

    Hi Stefan, I need to disable generally in my site the spam filter for all forms and all controls… I used this code but not run correctly:

    $form->add(‘label’, ‘label_state’, ‘state’, $texte[“DESC_ESTAT”]);
    $obj = $form->add(‘select’, ‘state’, $row[‘state’]);
    $obj->set_rule(array(‘required’ => array(‘error’,$texte[“MSG_ERROR_ESTAT”])));
    $obj->set_attributes(array(‘disable_spam_filter’ => ‘true’,));

    Thanks for your help

Comments are closed.