This support ticket is created 2 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
java script code
function copyval() {
var k=document.querySelector('input[name="wpcf-user-email"]').value;
document.querySelector('input[name="wpcf-user_email"]').value=k;
}
Hello. Thank you for contacting the Toolset support.
Can you please explain me the goal of copying the field value to another field while you click on the submit button?
- Do you want to display the field value that you copy to another field on frontend? if no:
We can use the Toolset form's hook cred_before_save_data hook and assign/copy the field 1 value to field 2 value. does that makes sense?
we have two email fields
One is the Main which is belong to WP users
The second is created by us (custom field)
we need both
when the user updates the secondary email in the user form, the main email should be updated directly with the same value.
So any email value entered in the second should be copied into the main.
So why you will require javascript, have you tried to use the Toolset form's hook cred_before_save_data?
add_action('cred_before_save_data', 'func_update_user_email',10,1);
function func_update_user_email($form_data) {
// if a specific form
if ($form_data['id']==99999) {
if (isset($_POST['secondary-email'])) {
$_POST['primary-email'] = $_POST['secondary-email'];
}
}
}
Where:
- Replace "99999" with your original form ID
- you can adjust the code as required with original field slugs for primary and secondary email
Can you please share problem URL and admin access details and for what user you want me to change the email address. Please share that user access details as well.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
The issue was you missed the "wpcf-" prefix before the custom field slug. So, the correct custom field slug will be: wpcf-second-user-email
I've adjusted the code as given under to your code snippet.
add_action('cred_before_save_data', 'func_update_user_email',10,1);
function func_update_user_email($form_data) {
// if a specific form
if ($form_data['id']==5392) {
if (isset($_POST['wpcf-second-user-email'])) {
$_POST['user_email'] = $_POST['wpcf-second-user-email'];
}
}
}
Can you please check now it works as expected at your end as well:
- hidden link