While using Rules Forms on a specific site I support, I noticed that certain actions were being fired when they weren't supposed to.

Debugging using Drupal Revisions and Rules debugger, I came through the following scenario:

1- Open a form active on Rules Forms
2- Change whichever fields needed
3- Open another form that contain the same ID (may be another content of the same type, for example)
4- The $_SESSION['rules_forms_form_values'][$form_id] will be overridden by the values of the second form
5- Submit the first form. Notice that any conditions that any condition that check the previous values is now comparing with the values for the second form instead.

The cause of this is that even if for different content, all forms of the same content type have the same ID, so the session only stores the values for one form at a time.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

caminadaf created an issue. See original summary.

caminadaf’s picture

I believe that setting every visitted form on the session would make it unsustainable (specially if they visit many forms but exit them instead of submitting). This would make the array values form the session not being removed.

As an alternative, I will study using the $form_state instead of using the SESSION, this way each for build values will be related to that form visit only.

caminadaf’s picture

Patched the suggested changes. I'll leave this patch here for now since it has the risk of impacting other people's work.

caminadaf’s picture

Added back the submit assetion on the test file.

caminadaf’s picture

Component: Rules » Code
Assigned: caminadaf » Unassigned
Status: Active » Needs review
dfranca’s picture

Status: Needs review » Reviewed & tested by the community

Tested the scenario described on the patch, with and without it, and the issue is fixed.
Also tested with other different rules to look for side effects, and all of them are working exactly as before.

Status: Reviewed & tested by the community » Needs work

  • caminadaf committed 9b80557 on 7.x-1.x
    Issue #2969591 by caminadaf, dfranca: Form build information on the...
caminadaf’s picture

Status: Needs work » Fixed

Commited based on @dfranca's tests

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.