Zebra_Form, a jQuery augmented PHP library for creating and validating HTML forms

Get the latest updates on this PHP library via RSS



You are currently browsing comments. If you would like to return to the full story, you can read the full entry here: “Zebra_Form, a jQuery augmented PHP library for creating and validating HTML forms”.

1396 responses to “Zebra_Form, a jQuery augmented PHP library for creating and validating HTML forms”

Follow the comments via RSS
  • Olivier Rochefort, 2015-06-23, 20:50

    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');
    $obj->set_rule(array(
      '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'))
    Reply
    • Stefan Gabos, 2016-01-14, 21:53

      This is now fixed. Thanks!

  • Matt, 2015-07-03, 06:51

    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.

    Reply
  • Sander, 2015-08-06, 12:40

    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

    Reply
    • Stefan Gabos, 2016-01-14, 20:34

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

  • Johan Smyth, 2015-09-16, 12:06

    Hi,
    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?

    Reply
  • Shabeer, 2015-11-10, 12:00

    Hi,

    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

    $('#form').data('Zebra_Form').validate();

    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.
    Shabeer

    Reply
    • Stefan Gabos, 2016-01-15, 00:53

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

      $('#form').data('Zebra_Form').validate();

      Thanks!

  • Natalie, 2015-12-17, 15:53

    Hi
    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.

    Reply
    • Natalie, 2015-12-17, 15:59

      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 $
      symbol)

    • Stefan Gabos, 2016-01-14, 20:31

      This is now fixed. Thanks!

  • Jaco Roux, 2016-01-12, 18:35

    Thanks for an excellent library.

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

    For example:

    set_rule(array(
        'dependencies' => array(
            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

    Reply
    • Stefan Gabos, 2016-01-12, 23:19

      I can confirm this and will look into it as soon as I can. Thank you!

    • Stefan Gabos, 2016-01-13, 00:45

      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)

    • Jaco Roux, 2016-01-13, 11:53

      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.

    • Stefan Gabos, 2016-01-13, 13:17

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

    • Jaco Roux, 2016-01-13, 13:42

      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.

    • Stefan Gabos, 2016-01-13, 14:19

      You are right, I’ll look into that today. Thanks!

    • Jaco Roux, 2016-01-13, 14:58

      Thanks a lot Stefan

    • Stefan Gabos, 2016-01-14, 11:25

      Should be fixed now. Let me know if it works. Thanks!

    • Jaco Roux, 2016-01-14, 14:57

      Thanks it works perfectly now, big thumbs up to you.

  • Natalie, 2016-01-24, 17:16

    Spoke to soon
    There is a problem with the field of type ’email’ and fields of type ‘number’

    If you fill in a form with a captcha but fill in the captcha incorrectly then the values in any field of type email or number are not retained on the screen when the captcha error message is displayed

    You can see this behaviour in your demo: http://stefangabos.ro/wp-content/demos/Zebra_Form/?example=registration&template=vertical

    Reply
    • Stefan Gabos, 2016-01-24, 23:51

      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!

    • Natalie, 2016-01-25, 16:36

      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).

    • Stefan Gabos, 2016-01-25, 19:16

      Should be ok now

    • Natalie, 2016-01-26, 16:08

      Yes working fine now. Thanks very much

  • Richard, 2016-02-07, 09:12

    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?

    Thanks!

    Reply
    • Richard, 2016-02-07, 09:27

      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)

    • Richard, 2016-02-07, 09:48

      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!

  • Charlie, 2016-02-17, 19:53

    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!

    Reply
    • Charlie, 2016-02-19, 05:25

      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.

  • sarath, 2016-02-29, 14:33

    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.

    Reply
    • sarath, 2016-03-01, 13:24

      $('#form').data('Zebra_Form').validate();,
      form validation is not working for me

  • Grüne Leuchte, 2016-03-10, 13:07

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

    Reply
    • Stefan Gabos, 2016-03-11, 11:31

      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'));
  • Tony, 2016-03-12, 06:39

    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.

    Reply
  • Jaco Roux, 2016-03-16, 15:42

    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.

    Example:
    $date->set_rule(array(
    ‘required’ => array(‘error’,$translation->getValue(“errRequired”)),
    ‘date’ => array(‘error’,$translation->getValue(“errDate”)),
    ));
    $date->set_attributes(array(
    ‘style’ => ‘width:50%’,
    ‘onBlur’ => ‘enableDae()’,
    ‘onChange’ => ‘jaarDatumToets()’, //DOES NOT WORK
    ‘onFocus’ => ‘clearDae()’,
    ));
    $date->format(‘Y/m/d’);
    $date->direction(true,1);

    Reply
  • ceskmm, 2016-03-18, 18:28

    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->add_options(array($estat_lst));
    $obj->set_rule(array(‘required’ => array(‘error’,$texte[“MSG_ERROR_ESTAT”])));
    $obj->set_attributes(array(‘disable_spam_filter’ => ‘true’,));
    $obj->disable_spam_filter();

    Thanks for your help

    Reply

Leave a Reply

Your email address will not be published
You can use <strong>, <em>, <a>, <img>, <code>
Characters are not case-sensitive