• 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)
  • hi @sporkme
    I think form data not change because they has already been sent.
    wpcf7submit — Fires when an Ajax form submission has completed successfully, regardless of other incidents.
    https://contactform7.com/dom-events/


    you can edit form data in many ways after submit, for example using FormData or you can hook with a filters like the spam or the validation or with the action wpcf7_before_send_mail https://contactform7.com/2020/07/28/accessing-user-input-data/

    • This reply was modified 3 years, 3 months ago by Erik. Reason: wrong link to FormData documentation
    Thread Starter sporkme

    (@sporkme)

    Yeah, I wasn’t really clear on when that fired – I assumed literally “on submit”, not “after form is submitted”, but the docs on all this are a bit sparse.

    I’ve seen that page on “accessing user data”, but I’m not at all clear how I’d send my altered field entry back.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Correct way to alter input field on submit’ is closed to new replies.