PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

"inputs" array isn't updated after pre-populate fields

  1. acsnaterse
    Member

    I have a form where one field of checkboxes is pre-populated with the contents of some posts (CPT "book").

    This works perfectly and in the frontend as well as in the back (edit area) I see all the fields (see screenshot http://l.uprise.nl/mnwdc ).

    One problem however, I've added a new book ("Cloud") lately. I see it in the frontend, but I don't see this one back in the selectbox of the merge fields (screenshot: http://uploads.uprise.nl/Screen_Shot_2012-07-18_at_15.07.18-20120718-150805.png). There are 5 books, but not "Cloud".

    Also when I dump the data of the $form object I see the "choices" are filled as it should be, but the "inputs" array misses the "Cloud" item.

    What can this be, and how can I update this "inputs" field, since just updating this array in the pre_render filters doesn't seem to work.

    Thanks!

    Posted 11 years ago on Wednesday July 18, 2012 | Permalink
  2. The first link does not work without a login for your Google AFYD account? Can you post that somewhere public please?

    Can you post the code you're using to pre_render that checkbox list? Post at pastie.org or pastebin.com

    Posted 11 years ago on Wednesday July 18, 2012 | Permalink
  3. acsnaterse
    Member

    The link of the first screenshot is: http://uploads.uprise.nl/Cloud-20120718-150530.png

    And here's the code: http://pastebin.com/FCafeyyk

    Posted 11 years ago on Thursday July 19, 2012 | Permalink
  4. acsnaterse
    Member

    Another update which maybe helps you with finding the bug (since it seems to be a bug).

    When I edit the form manually and I add an empty (or other) option, the "inputs" array seems to be updated and I see all of the inputs in the merge tags select field.

    So probably after "pre rendering" the form the inputs array isn't updated. Maybe this is correct behavior (?), but is there a way/filter to also update the "inputs" array?

    Posted 11 years ago on Friday July 20, 2012 | Permalink
  5. Do you mean you are trying to permanently update the checkbox list which is saved in your form, using the gform_pre_render filter? You want to update the form? The gform_pre_render filter will not update your form.

    Posted 11 years ago on Friday July 20, 2012 | Permalink
  6. acsnaterse
    Member

    Yes, when there's a new book, the form itself will update automatically (like I want), but not the merge-fields in the backend.

    Is there a way to do so? Which filter do I need for that?

    Posted 11 years ago on Friday July 20, 2012 | Permalink
  7. You cannot update your form by using the pre-render filter. That is for displaying information before the form is shown to the visitor. You're trying to programmatically modify your form which is not supported by any existing filters that I know of. I pinged one of the developers and maybe they will point out something I am unfamiliar with. If I understand what you're trying to do, I don't believe it's possible.

    Posted 11 years ago on Friday July 20, 2012 | Permalink
  8. Hi, acsnaterse,

    I am not sure if we entirely understand what you are trying to do. I want to make sure we are clear.

    1. You have created a custom post type of boek (book).
    2. You have posts associated to that custom post type.
    3. When the form loads from the site, there is a checkbox displayed which has the values of the book titles pulled from the wp_posts table for post_type='boek'. This is populated by the gform_pre_render filter. This part is working correctly.
    4. The gform_admin_pre_render filter is used so when you go into the admin, the checkbox is populated in the form editor. This part is working correctly.
    5. You have added a new post for the book Cloud and associated it to the post type of 'boek'.
    6. The new book Cloud shows on the form when on the site.

    I think the next part is where the confusion on our end begins.
    7. Does the new book show in the admin when you go to edit the checkbox field?
    8. What do you mean by the new book not showing in the "selectbox of the merge fields" and the "merge-fields in the backend"? I couldn't tell what the screenshot you provided was showing.
    9. When you are viewing the $form object and looking at the choices and inputs, is this when the form is loading or when loading it in the admin? Are you doing this in the different render filters?

    I am trying to reproduce what you are doing so I can understand it better.

    Thanks.

    Posted 11 years ago on Friday July 20, 2012 | Permalink
  9. acsnaterse
    Member

    Thanks for pointing this out so clear :-) Until step 7 everything works indeed and is correct.

    7. Yes, I see the book in the admin (screenshot http://uploads.uprise.nl/Bewerk_formulieren_%E2%80%B9_ICTRecht_%E2%80%94_WordPress-20120721-142224.png)

    8. In the notifications screen there are several selectboxes with some merge fields, to insert variables from the form in the notification messages. This is a screenhot of one of those selectboxes: http://uploads.uprise.nl/Screen_Shot_2012-07-21_at_14.24.12-20120721-142449.png

    Now "Cloud" is in the selectbox, but is because of manually adding/saving this field (as described above in my former response). When a new post/book is added these fields in the selectbox are not automatically updated.

    9. Both, frontend and backend. Indeed I print the $form object in the filter function.

    I hope this clarifies it a bit?

    Thanks!

    Posted 11 years ago on Saturday July 21, 2012 | Permalink
  10. Just a note, I haven't forgotten this. I had to switch gears and work on another issue. I should do some more on this today.

    Posted 11 years ago on Wednesday July 25, 2012 | Permalink
  11. Hi, acsnaterse,

    Sorry it took so long to get back with you. The form notifications page doesn't honor the field as you have set it up with the functions in the gform_pre_render and gform_admin_pre_render hooks. As you saw, the inputs collection for the field isn't populated. Even if you did populate this in your function, the only values that would show in the merge tag drop down would be ones that showed in the form editor when you saved. So, this still doesn't help you because it isn't really feasible to keep going into the admin and saving the form.

    If your goal is just to display the values that the user chose while submitting the form, then you can simply add the merge tag for the checkbox field, not the individual checkbox choices. When that is selected, the values that the user has selected are shown in a comma-delimited list.

    I did look into having the notifications page use those hooks, but we are making some changes soon to how the form settings/notifications are laid out and we don't want to make any big changes to it right now. I have mentioned the need for those hooks to also be fired on the notifications page to the rest of the team, so we will look into doing that with our planned changes. I know this doesn't solve your immediate issue, but at least you know it is on our radar.

    And if you would like to populate the inputs collection anyway, I have a modified version of your function which does so. You can take a look at that at this link: http://pastie.org/4360726

    Posted 11 years ago on Monday July 30, 2012 | Permalink
  12. acsnaterse
    Member

    Hi Dana,

    Thanks for you reply. Would be great to have such filters in the future, so I'll just wait for that ;-) In the meanwhile I can use your fix.

    Thanks a lot!
    Arjan

    Posted 11 years ago on Tuesday July 31, 2012 | Permalink
  13. Thanks for the update Arjan.

    Posted 11 years ago on Tuesday July 31, 2012 | Permalink

This topic has been resolved and has been closed to new replies.