add_filter('gform_pre_validation_13', 'populate_departure_date');
add_filter('gform_pre_submission_filter_13', 'populate_departure_date');
add_filter('gform_admin_pre_render_13', 'populate_departure_date');
add_filter('gform_pre_render_13', 'populate_departure_date');
function populate_departure_date($form)
{
    $today = strtotime(date('Y-m-d'));
    foreach ($form['fields'] as &$field) {
        if ($field->id == 37) {
        $pid = $_POST['post_id'];
        session_start();
        if (!isset($_SESSION['post_id'])) {
            $_SESSION['post_id'] = $pid;
        }

        if (have_rows('small_group_journey', $pid)):
            while (have_rows('small_group_journey', $pid)):the_row();
                if (!empty(get_sub_field('start_date/end_date'))) {

                    $dateS = explode('-', get_sub_field('start_date/end_date'));
                    if (strtotime($dateS[0]) >= $today) {
                        $choices[] = array('text' => date('F j Y', strtotime($dateS[0])) . ' - ' . date('F j Y', strtotime($dateS[1])), 'value' => date('F j Y', strtotime($dateS[0])) . ' - ' . date('F j Y', strtotime($dateS[1])));
                    }
                }
            endwhile;
        endif;

        $field->placeholder = 'Fixed Departure Dates';

        $field->choices = $choices;
    }
}

return $form;

}

I have this code in my function.php and

do_shortcode('[gravityform id="2" title="false" description="true" ajax="false" field_values="trip_name=' . $trip_title . '&departure_date=' . $_POST['start_date'] . '-' . $_POST['end_date'] . '" tabindex="23" ]');

ALL thing is working initially [Initial Populated field)
but, After I clicked submit and the field gets error[After submission][1]: https://i.stack.imgur.com/dkMhv.png
Fields disappear.
I have tried preserving by using session variables but I can only preserve the page title.
Any solution

Read more here: gform dynamically populated not working after the field error?


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: