During working on the profile2 module I added registration integration, however once a field with "add-more" functionality is added and 'add-more' button appears. This button falls back on a multistep form once there is no JS, however as the form initially is no multistep form - it looses it's form values.

Thus it's impossible to cleanly add fields to the registration form that way.

Possible fixes would be
1) the new form-value keeping method suggested in #622922: User input keeping during multistep forms
2) using a clean form workflow that's working regardless the form is going through multiple steps or not. For the discussion regarding the right workflow see: http://drupal.org/node/367006#comment-2272166

Personally I favour 2) as I think 1) would introduce possible troubles with real multistep forms (see issue).

If we make storage more straight forward to use (-> #367006: [meta] Field attach API integration for entity forms is ungrokable) we could easily move the data (-> $user) to the storage by default. Then everything would stay working regardless the form workflow involves multiple steps or not.

Note:
* This problem is in d6 too. While fixing this probably involves too much changes for d6, we should really fix it for d7 right now.
* This problem probably affects most of drupal's forms as usually they are not prepared to work with multiple steps. Thus altering it to do so won't work.

CommentFileSizeAuthor
#10 form_multiple.patch3.64 KBfago
#9 form_multiple.test3.64 KBfago

Comments

fago’s picture

ehm, linked the wrong issue for making storage more straight forward -> #634440: Remove auto-rebuilding magic for $form_state['storage']

effulgentsia’s picture

Personally I favour 2) as I think 1) would introduce possible troubles with real multistep forms (see issue).

I'd like to understand 2) more, and am open to it if it allows form construction/alter/process/validate/submit functions to be written in a straightforward way. But I disagree that 1) would introduce problems with multistep forms. There's already a patch on that issue (#65) that works correctly, and ongoing refinements to it would need to also work with multistep forms before the issue is ready for commit.

sun’s picture

Title: registration form breaks with add-more buttons » Fields cannot be attached to non-multi-step forms
Component: user system » forms system
Issue tags: +D7 API clean-up
fago’s picture

Title: Fields cannot be attached to non-multi-step forms » registration form breaks with add-more buttons
Component: forms system » user system
Issue tags: -D7 API clean-up

Let's discuss that in the issue over there -> I've responded there.

fago’s picture

Issue tags: +D7 API clean-up

ops, cross post.

sun’s picture

Issue tags: +D7 Form API challenge

.

fago’s picture

#622922: User input keeping during multistep forms landed. I just gave this a test again and it still doesn't work. This is due to the field API, which still forces the form to have an own persistence mode:

 function field_multiple_value_form($field, $instance, $langcode, $items, &$form, &$form_state) {
+  // This form has its own multistep persistance.
+  if ($form_state['rebuild']) {
+    $form_state['input'] = array();
+  }
sun’s picture

I suggest to add a hook_form_alter() implementation to form_test module for the user registration form (which is a nice prototype of a non-multistep form) that adds a multiple value field to the form, and add a test that ensures proper form processing and rebuilding for the altered form.

The patch in #370537-78: Allow suppress of form errors (hack to make "more" buttons work properly) contains some nice fake multiple value field widget code, which we can copy + paste into a form_alter. If this test fails, then this issue needs to be bumped to critical.

fago’s picture

StatusFileSize
new3.64 KB

Well the problem doesn't appear with regular rebuilds as long as they don't scratch the input values by setting $form_state['input'] = array();

Thus I implemented a test case, that shows it's working with a basic rebuild, but it fails when using the field API. Because the field API demands the form to have its own multistep persistence as I noted in #7, letting the use case of profile2 (registration integration) fail.

Setting to "needs review" to let the test bot run.

fago’s picture

StatusFileSize
new3.64 KB
fago’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, form_multiple.patch, failed testing.

sun’s picture

Title: registration form breaks with add-more buttons » Registration form breaks with add-more buttons
Priority: Normal » Critical

As this bug seems to break and prevent evolution of a new Profile module, bumping to critical.

fago’s picture

effulgentsia’s picture

Status: Needs work » Closed (duplicate)

Please add the failing test from #10 to #735808: fix multiple field value form to work with form API persistence and I think we're golden.

gisle’s picture

Issue summary: View changes
Issue tags: -D7 API clean-up +API clean-up

Renaming non-canonical duplicate tag. See #2426171: Multiple tags similar to 'API clean-up' for background.