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:
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.
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?
$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 🙂
The topic ‘Empty field label/name’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2022 Advanced Custom Fields.