wp-forms
wp-forms copied to clipboard
Field name conflict with custom post type
This is probably not a real issue for wp-forms but I just lost an hour resolving the following bug and I just wanted to document it somewhere.
In my form, I had a field named member
. I also have a custom post type with the same name. I don’t know exactly why but if I submit the form and the validation doesn’t pass, I get redirected to the correct URL with the 404 template being displayed. I’ve tested with other custom post types and the behaviour is similar. It doesn’t seems to happen with fields named post
or page
though.
I’ve renamed the field "member_type" and now it works perfectly. Do you have any idea where this conflict could come from and if it could be prevented by wp-forms somehow?
Thanks for this great and highly customisable API by the way.
Yes. This stuff happens inside WordPress core (not inside this plugin). My solution for this issue — just prefix all name attributes with my custom form prefix.
wp_register_form( self::$form_name, array( __CLASS__, 'register_form' ) );
// Somewhere inside register_form()
->add_element(
WP_Form_Element::create( 'text' )
->set_name( self::$form_name . 'name' )
// ...
P. S. I think the author forgot about this repository and now I create forked version of this (you can find it in my Github profile). I've added few custom elements such as markup
— any custom html markup inside your form. Support AJAX-form submitting. And now try to fix checkboxes
element - they don't save cheched
statuses after submit with errors.
Issue about cheched checkboxes fixed: https://github.com/jbrinley/wp-forms/issues/8
Thanks for the tip! The same problem occurs with radios by the way.