Support

Account

Home Forums Front-end Issues Displaying date picker value in html form

Helping

Displaying date picker value in html form

  • I have a simple ACF field group that I am displaying as a form on the front end. My users will use the form to enter information about their fitness test. In the form I am using 2 date picker fields. The form code shows the date selection object. However the problem I am having is displaying the date values after the form is saved.

    Here is the form code for the date fields;

    <?php
    // get raw date
    $start_date = get_field(‘test_start_date’, false, false);
    $end_date = get_field(‘test_end_date’, false, false);

    // make date object
    $start_date = new DateTime($start_date);
    $end_date = new DateTime($end_date);?>

    Fitness Test Start Date: <?php echo $start_date->format(‘j M Y’); ?>
    <input class=”fit_test_results_input” type=”date” name=”test_start_date” value=”<?php $start_date; ?>” size=”20″ />

    Fitness Test End Date: <?php echo $end_date->format(‘j M Y’); ?>
    <input class=”fit_test_results_input” type=”date” name=”test_end_date” value=”<?php the_field(‘test_end_date’); ?>” size=”20″ />

    For the development process I am saving dates on the backend, since I have not completed the code to save the entries made on the front end. On the first line the saved date is showing correctly. It is only when attempting to display the saved date in the form input field that I get no output. I want to be able to remove the first line and only display either an empty field prior to the date being saved, and then the saved date when returning to the form.

    Thanks!

Viewing 1 post (of 1 total)

The topic ‘Displaying date picker value in html form’ is closed to new replies.