• Resolved wpman

    (@iwpman)


    Hi,
    Because my value is dynamic. I try to insert dynamic value to hidden field via API ,but I don’t know how to do?This is testing code,but it didn’t work.


    add_filter( 'caldera_forms_update_field_hidden','insert_value');
    function insert_value($field){
    $value="This is dynamic value";
    $field['value']=$value;
    return $field;
    }

    https://www.ads-software.com/plugins/caldera-forms/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Josh Pollock

    (@shelob9)

    That filter is not correct. If you wanted to target a specific field, by its slug, you can do that.

    Lets say your form’s slug was “api” then you would use the filter “caldera_forms_render_get_field_slug-api” or if you wanted to target all hidden fields you could use “caldera_forms_render_get_field_type-hidden”

    See this example: https://docs.calderaforms.com/caldera_forms_render_get_field_type-field_type/

    Also, these filters are documented inline here: https://github.com/Desertsnowman/Caldera-Forms/blob/b90be47a667d5493d0c6509e57c7be767136b63e/classes/core.php#L3680-L3706

    Thread Starter wpman

    (@iwpman)

    Thanks. You’ve been very helpful

    Thread Starter wpman

    (@iwpman)

    Hi Josh,
    Did I miss something? I put my form in bbpress forum every page.I want to get current forum id to specific field,but it didn’t work.I get nothing from specific field after submitting form.If I replace

    $field['config']['default'] = bbp_get_forum_id();//get dynamic value

    with

    $field['config']['default'] = "8256";

    I can get the 8256 value from specific field ,but forum id is dynamic. Did I miss something?
    If I echo it , it will display correct forum id value,but I get nothing from specific field after submitting form.

    $field['config']['default'] = bbp_get_forum_id();//get dynamic value
    echo $field['config']['default'];//it will display correct forum id value

    This is my script

    add_filter( 'caldera_forms_render_get_field_slug-parent','parent_value');
    function parent_value($field){
    $parent_value= bbp_get_forum_id();
    $field['config']['default'] = bbp_get_forum_id();
    return $field;
    }

    Plugin Author Josh Pollock

    (@shelob9)

    When you said you echoed bbp_get_forum_id() in what context were you echoing it?

    Did you do it in the callback, like this:

    add_filter( 'caldera_forms_render_get_field_slug-parent','parent_value');
    function parent_value($field){
    $parent_value= bbp_get_forum_id();
    var_dump( $parent_value );
    return $field;
    }

    ?

    If I’m reading the source correctly it uses the global $wp_query object to find the forum ID. That object should be set when that filter runs, but I’m just glancing at source, not actually testing that assumption, which is a big assumption.

    Thread Starter wpman

    (@iwpman)

    Hi Josh,
    Thanks for your help.I echo $field['config']['default']; to test , like callback that it will display correct forum id value. But when I run my script,I still get nothing from specific field after submitting form.How to set object when that filter runs ?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘insert dynamic value to hidden field.Which API ?’ is closed to new replies.