• Hi,

    I am having some issue with the rendered field.
    It does show the data but when validating the field it is empty.
    It produces an error that it is required even if there is a value selected.

    This is my code

    —–

    add_filter(‘caldera_forms_render_get_field_slug-studymode’, ‘cf_get_data_studymode_csu’);
    function cf_get_data_studymode_csu($field) {
    if (isset($_POST[‘post_id’])) {
    $postid = $_POST[‘post_id’];
    } elseif (isset($_GET[‘course_id’])) {
    $postid = $_GET[‘course_id’];
    }

    $results = wp_get_post_terms($postid, ‘studymode’, array(“fields” => “all”) );
    $field[‘config’][‘option’] = array();
    foreach ( $results as $key => $data) {
    $field[‘config’][‘option’][] = array(
    ‘value’ => $data->name,
    ‘label’ => $data->name
    );
    }

    // return the field to the form
    return $field;
    }

    —–

    I can’t figure out the issue. Do you have any idea why it’s not working?
    Maybe I have some code issue.

    Thanks.

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter nicheru

    (@nicheru)

    Hi,

    When I remove this part of the code it works, so I just hardcoded the post id.

    —–

    if (isset($_POST[‘post_id’])) {
    $postid = $_POST[‘post_id’];
    } elseif (isset($_GET[‘course_id’])) {
    $postid = $_GET[‘course_id’];
    }

    —–

    Is there a way where I can pass $form values in the function? I tried add $form as parameter but it is not working.

    Thanks.

    Thread Starter nicheru

    (@nicheru)

    Hi,

    The issue was that caldera_forms_render_get_field_slug is called again after submitting and the post id is not available anymore.

    Is it really called twice? I am just confused since the value for the select is already there when loading the form.

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Issue with caldera_forms_render_get_field_slug’ is closed to new replies.