Skip to content

Instantly share code, notes, and snippets.

@snrjosh
Created March 22, 2024 16:39
Show Gist options
  • Save snrjosh/de7c21c201bda4c779c1b3af62e03b47 to your computer and use it in GitHub Desktop.
Save snrjosh/de7c21c201bda4c779c1b3af62e03b47 to your computer and use it in GitHub Desktop.
WPForms - Populate a field from another field on same form
<?php
/**
* Populate a field from another field on same form
*
* @link https://wpforms.com/developers/how-to-pre-populate-fields-in-the-same-form/
*/
add_action( 'wpforms_wp_footer_end', function() {
?>
<script>
jQuery(function($){
var formID = 22397; // Change form ID
var faxNumber = 7; // Fax number field ID to grab value
var faxEmail = 8; // Fax email field ID to pass value to
$( '#wpforms-' + formID + '-field_' + faxNumber ).on( 'change', function() {
$( '#wpforms-' + formID + '-field_' + faxEmail ).val($(this).val().concat("concatenate some text here"));
});
});
</script>
<?php
}, 10 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment