Support

Account

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

Solved

Loading field values on front-end form

    • japel

    • August 26, 2013 at 8:29 pm

    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

    • Elliot

    • August 27, 2013 at 2:18 pm

    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/

    • japel

    • August 27, 2013 at 8:07 pm

    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

    • japel

    • August 27, 2013 at 10:20 pm

    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

    • japel

    • August 27, 2013 at 10:29 pm

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

    • japel

    • August 29, 2013 at 10:25 pm

    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

    • Elliot

    • August 30, 2013 at 2:49 pm

    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)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.