Support

Account

Home Forums Front-end Issues Loading field values on front-end form

Solved

Loading field values on front-end form

  • I would like to preload custom values to a front-end form made with acf_form() function.

    Is there any way to accomplish this without javascript?

    Thanks in advance!

    Jan

  • Hi @japel

    You can use a filter called acf/load_field to hook in and modify the value of the $field.

    Docs can be found here:
    http://www.advancedcustomfields.com/resources/filters/acfload_field/

  • Hi elliot!

    Thank you, that sounds nice!
    Kind of embarrassing, you know how I tried to help myself?

    I started using ob_start() and loaded the rendered form to a string, and then replaced the values using str_replace() 😛

    This sounds a bit more elegant 😛

    Thanks!

    Jan

  • Hi elliot,

    I tried using that filter, but it just don’t hook. 🙁

    acf/load_value works fine and hooks but if I try using acf/load_field it just doesn’t hook.

    What could I be doing wrong?

    Best regards,

    Jan

  • my bad, my bad! got it working… it was an xdebug problem… sorry!

  • Dear elliot,

    now I have another question regarding checkbox values.

    I’m saving acf form data with ajax to postmeta, for a checkbox field with two checkboxes

    value, anothervalue

    the data stored by acf if both are checked is:

    a:2{i:0;s:5:”value”;i:1;s:12:”anothervalue”;}

    when I reload the page, retrieving postmeta and
    set $field[‘value’] to a:2{i:0;s:5:”value”;i:1;s:12:”anothervalue”;}
    the checkboxes are not checked 🙁

    what am I doing wrong here?

    Thank you and best regards,

    Jan

  • Hi @japel
    In the database, the value saves as a:2{i:0;s:5:”value”;i:1;s:12:”anothervalue”;}. This is technically a string, but when WP loads the value, it converts it to an array!

    When you update your value, don’t update it with a string, update it with an array.
    The array should contain the values such as “value” and “anothervalue”

    Let me know if you need any extra help.

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Loading field values on front-end form’ is closed to new replies.