Home Forums General Issues Empty field label/name


Empty field label/name

  • Hello,

    I am using ACF in some ‘not-normal’ wordpress ‘site’ and found a bug which could be just overlooked in normal use.
    The bug is:
    You can create a field without its label. When you save the field group, the field is created though. It has no label, and also NO NAME! so the meta_key column in database for this field remains EMPTY (but both, field label and field name fields are marked with red ‘*’ – as required). So I decided to do some more tests and found that: when you enter some field label, name is created automatically by js. When I deleted it, the field was created with empty name again!

    It is really not a good way to handle this, and why it’s double-bad for me:
    I need the values from custom fields in javascript on frontend, taken by ajax call. And I use a wordpress with ‘SHORTINIT’, then have my custom function to get field values with custom sql queries (using $wpdb). To make it easy accessible in js, I convert the fields to one object (stdClass) with properties like field_name->field_value. Of course it caused an error when the key in object was empty!

    Possible (and really simple) solution which would satisfy me:
    Just not create the field with empty label, and when the label is passed but without the name, create the name automatically in php before save also, not only in js on editing page.

    It would be great if you could fix this in some future version.

    Thanx for great and very functional plugin.


  • Hi @szaleq

    Thanks for your feedback. I don’t really understand why you are creating custom fields which do not have a label or name, this doesn’t make any sense to me.

    I’m not sure If I will add this to the to-do as so far, you are the first user to raise this issue.

    Perhaps you could think about hooking into some of the ACF hooks such as acf/update_field to run your own validation?


  • Thanks for your replay.

    This doesn’t make any sense to me also, to create a field with empty label and name. But, there is a theory that any software should be just ‘idiotproof’… So one should not be able to do something like that. Personally I just created an empty field by accident, it saved and broken my site.
    It is some kind of a standard in such a software, that the inputs are validated, because the user can really be ‘stupid’ or just overlook something. And, as I wrote, both fields are marked as required. But they are not in fact.

    So, again, I think it should done in the core of the plugin as there are two lines of code needed to check if the value is empty. And to create an empty name if the label is filled there are built-in functions in wordpress (‘sanitize_title’ ? ). I don’t really understand, why you don’t think it should be fixed?


  • Hi @szaleq

    Thanks for the feedback.
    I’ll definitely consider it.

    Can you please elaborate a bit more on this:
    “I just created an empty field by accident, it saved and broken my site.”


  • As I wrote in my first post, I use my wordpress instalation in a non-standard way. It’s used because it provides a great amount of useful functions + admin interface, but on the frontent I have my custom .php files which load wordpress with the SHORTINIT param. And I have also my custom database queries to get the ACF fields, because the plugins are not loaded on SHORTINIT. As I wrote I need to pass the fields as an object to ajax response, to have it in my frontend javascript, so I create an object of fields, $obj->field_name = 'field_value'. If there was an empty field without name, without label, it caused error because of trying to create an object property with empty name

    $prop_name = null;
    $obj->$prop_name = $field_val; // error!

    Of course, I can just check if the field name is not empty, but I think it should be done during saving a field, because I’m sure no one needs a field without name, but one can create it ‘by accident’.

    Just for rules, logically when the field is marked as required, and it really is required, it should be required.

    Please consider adding this one or two lines of code, in the next version 🙂

  • Hi @szaleq

    Thanks for the feedback. Yes, I do think some JS validation is needed and I’ll be adding it. Can’t guarantee it will make 4.3, but perhaps 4.3.1

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Empty field label/name’ is closed to new replies.