Hi @mattmcca
Thank you for response!
I checked your form and code. If you want to get user email into the select field, all that is needed is a small change in the code that you are already using. You’d jus tned to change these lines
'label' => $user->user_login,
'value' => $user->user_login,
to this
'label' => $user->user_login,
'value' => $user->user_email,
This way, the “display” of drop-down list would still be usernames but the option value for each of them would be e-mail address.
Having them there, you could actually use that select field directly for sending Forminator e-mail notification (setting that select field as “Recipient”) without the need for any additional hidden field.
If you still want to populate hidden field with the e-mail address from selected drop-down field, it’s a bit tricky and I would recommend using regular “input” field instead of the “hidden” field. This is because hidden fields are now validated and while we could use JS to populate it with currently selected value of drop-down, that value would not be saved anyway – because it would not be set in hidden field configuration.
Using a regular “input” field overrides that restriction.
Then it can be populated from “Select” field with a bit of additional code (you can add it to your existing code file):
add_action( 'wp_footer', 'forminator_populate_input_from_select', 99 );
function forminator_populate_input_from_select() {
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$('.populate-list select').on('change',function(){
if($(this).val() != "default"){
$('.hidden-populate input').val($(this).val());
}else{
$('.hidden-populate input').val('');
}
});
});
</script>
<?php
}
You would also need to:
– in select field (the source field) set this as Additional CSS class in “Styling” section (note no dot at the beginning)
populate-list
– and in the input field set this as Additional CSS class in “Styling section (again, no dot at the front):
hidden-populate
To make that input field hidden, you can simply add following CSS to the site:
.hidden-populate {display:none;}
Note: the form must NOT have “Load form using AJAX” option enabled – it has to be disabled, otherwise the shared JS will not work correctly.
—–
That being said, if you want to NOT include email as a value of select field, then populate other field with e-mail fetched automatically in the background based on the username selected in select – that’s a whole different story and it would require more complex development, including AJAX requests to actually fetch user e-mail based on username; this would be out of the scope of this support, I’m afraid, so I hope proposed solution would work fine for you (I tested it on my end before sharing).
Best regards,
Adam