Correct way to alter input field on submit
-
Looking at the examples here:
https://contactform7.com/dom-events/
I don’t see how to actually alter/modify an input field on submit.
I have this firing, and it does find the right input field, set the right selector for jquery, but it does not update the field. Should it, or should I be digging around in filters for this instead?
// alter date format on schedule submissions document.addEventListener( 'wpcf7submit', function( event ) { // this is all the form values var inputs = event.detail.inputs; // loop on all inputs for ( var i = 0; i < inputs.length; i++ ) { // we're looking for the datepicker fields which are all "date-something" if(/date-*/i.test(inputs[i].name)) { // convert date format - we want a day name, supplied string format: '07/31/2021 03:00 PM' var newdate = moment(inputs[i].value).format("dddd, MMMM Do YYYY, h:mm:ss a"); var formfield = inputs[i].name; jQuery('input[name="' + formfield + '"]').val(newdate); alert( 'date: ' + newdate + ' form name: ' + formfield); break; } } }, false );
For various reasons, I can’t alter the format in the datepicker plugin that’s filling the field, so I have to act on the value it puts in the input field.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Correct way to alter input field on submit’ is closed to new replies.