• Using contact form 7 on my website, would like to retrieve the form submission date as an input value to use in “Jetpack CRM” for a custom field. I want to avoid that the user has to select the date with a date picker.
    Until now i only managed to get the current date value with [hidden today_date _date] that i can use in email templates, but this is not the thing i need.
    What i tried so far (after reading How do I change the value of text field in wordpress contact form 7 using javascript):
    In contact form 7, i added the field <label> [text submission_date id:submissiondate ""] </label>, hoping that the javascript would fill out the empty quotes with the dateTime value.
    With the plugin “WP Headers and Footers” i added the script

    var today = new Date();
    var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
    var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
    var dateTime = date+' '+time;
    document.getElementById("submissiondate").value = dateTime;

    I tried the script in the header, in the body and in the footer.
    The result is always: an empty form field and a js error:

    Uncaught TypeError: document.getElementById(…) is null

    Can anybody help me with this?

    • This topic was modified 2 years, 7 months ago by pigsound. Reason: typesetting correction, topic tags
    • This topic was modified 2 years, 7 months ago by pigsound.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Takayuki Miyoshi

    (@takayukister)

    Why don’t you simply use a date form-tag? You can hide it with CSS if you don’t want users to see it.

    Thread Starter pigsound

    (@pigsound)

    hi takayuki,
    i followed your advice and tried entering
    [date submission_date id:submissiondate ""]
    (leaving the script in WP Headers and Footers unchanged)
    but this throws the same error

    Uncaught TypeError: document.getElementById(…) is null

    i just don’t know how to get the actual date of filling out the form into the field.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get current date value to populate an input field’ is closed to new replies.