-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Field name error #38
Comments
@christianmagill is that the entire code you use to generate this field? Can you include the code used in the repeater as well? The code as written currently yields the following config array on Array
(
[key] => group_documents
[title] => Documents
[fields] => Array
(
[0] => Array
(
[type] => text
[name] => documents_title
[label] => Documents Title
[key] => field_documents_documents_title
)
[1] => Array
(
[type] => repeater
[name] => documents
[label] => Documents
[key] => field_documents_documents
[layout] => block
[button_label] => Add Document
[sub_fields] => Array
(
)
)
)
[location] =>
) I'm also wondering if this is ACF Builder or if ACF itself is "helping" when it detects the group name at the beginning of the field name and is striping it off. I've not run into that functionality before though. |
|
Ok so that yields: Array
(
[key] => group_documents
[title] => Documents
[fields] => Array
(
[0] => Array
(
[type] => text
[name] => documents_title
[label] => Documents Title
[key] => field_documents_documents_title
)
[1] => Array
(
[type] => repeater
[name] => documents
[label] => Documents
[key] => field_documents_documents
[layout] => block
[button_label] => Add Document
[sub_fields] => Array
(
[0] => Array
(
[type] => text
[name] => title
[label] => Title
[key] => field_documents_documents_title
)
[1] => Array
(
[type] => file
[name] => file
[label] => File
[key] => field_documents_documents_file
)
)
)
)
) So you can see we end up with two fields with the same key: I'm thinking I should add some sort of duplicate key exception maybe, so you'd be made aware of this right away. If you removed the "documents_" string from the field name it would fix this issue: $documents = new FieldsBuilder( 'documents');
$documents
->addText('title')
->addRepeater( 'documents', [
'layout' => 'block',
])
->addText('title')
->addFile('file')
->endRepeater()
->setLocation('post_type', '==', 'page'); Yields: Array
(
[key] => group_documents
[title] => Documents
[fields] => Array
(
[0] => Array
(
[type] => text
[name] => title
[label] => Title
[key] => field_documents_title
)
[1] => Array
(
[type] => repeater
[name] => documents
[label] => Documents
[key] => field_documents_documents
[layout] => block
[button_label] => Add Document
[sub_fields] => Array
(
[0] => Array
(
[type] => text
[name] => title
[label] => Title
[key] => field_documents_documents_title
)
[1] => Array
(
[type] => file
[name] => file
[label] => File
[key] => field_documents_documents_file
)
)
)
)
) Alternatively you could add a custom key to the title field in the repeater: $documents = new FieldsBuilder( 'documents');
$documents
->addText('documents_title')
->addRepeater( 'documents', [
'layout' => 'block',
])
->addText('title')
->setKey('document_title')
->addFile('file')
->endRepeater() That yields: Array
(
[key] => group_documents
[title] => Documents
[fields] => Array
(
[0] => Array
(
[type] => text
[name] => documents_title
[label] => Documents Title
[key] => field_documents_documents_title
)
[1] => Array
(
[type] => repeater
[name] => documents
[label] => Documents
[key] => field_documents_documents
[layout] => block
[button_label] => Add Document
[sub_fields] => Array
(
[0] => Array
(
[type] => text
[name] => title
[label] => Title
[key] => field_documents_documents_document_title
)
[1] => Array
(
[type] => file
[name] => file
[label] => File
[key] => field_documents_documents_file
)
)
)
)
) |
Probably the alternative approach is the way to go. I don't want "title" at the root level to avoid clashing with other possible groups. Are there character limits to how long a key can be? How about including "group" in the naming to differentiate? |
I have run into an issue before when the SUHOISN PHP module is enabled and there is a limit on POST var names. See this stack overflow link Maybe there is a better word than title for both, such as document name or document headline or maybe even document section title. Or maybe staying consistent and inside the repeater and name those fields document_title and document_file, that would generate: Array
(
[key] => group_documents
[title] => Documents
[fields] => Array
(
[0] => Array
(
[type] => text
[name] => documents_title
[label] => Documents Title
[key] => field_documents_documents_title
)
[1] => Array
(
[type] => repeater
[name] => documents
[label] => Documents
[key] => field_documents_documents
[layout] => block
[button_label] => Add Document
[sub_fields] => Array
(
[0] => Array
(
[type] => text
[name] => document_title
[label] => Document Title
[key] => field_documents_documents_document_title
)
[1] => Array
(
[type] => file
[name] => document_file
[label] => Document File
[key] => field_documents_documents_document_file
)
)
)
)
) |
Cool, I see your point... I probably need to revisit my naming conventions in general to stop these kind of issues. Much thanks for your help! |
I'm running into an issue with this code...
ACF Builder seems to get confused when you are using the field group name as part of the field name. "documents_title" ends up getting the field name of "title".
The text was updated successfully, but these errors were encountered: