[Resolved] Copy field value to another field if generic checkbox is checked
This support ticket is created 3 years 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.
I have a form that takes a billing address with slug 'billing-address'.
I have two more fields that take service addresses - 'residential-service-address' and 'commercial-service-address'.
I want to have a generic checkbox for each service address('res-serv-address-copy' and 'com-serv-address-copy'), that when checked will hide the associated service address field and copy the billing address field value to the appropriate service address field.
You can achieve this with some basic JavaScript (or jQuery, which will be available on a page with a form).
You'll need to add an on change event listener to the generic checkboxes to capture when they are checked (see hidden link), and then you can copy the content from the billing-address field to the corresponding address field (you can use hidden link to both get and set the values).
It's a good idea to use the window.load event to trigger your code (which you can add in the custom JS section of your form), like so:
( function( $ ) {
$( window ).on( "load", function(){
// add your jQuery code here
});
})( jQuery );
If you are not comfortable writing jQuery (as above) or Javascript you can contact a developer familiar with Toolset on our contractors page (https://toolset.com/contractors/), although as it is not specific to Toolset any developer should be able to provide a solution.
I don't have a budget for hiring another developer, and I am not strong with jquery/javascript.
The selling point for toolset is:
"Toolset Helps WordPress Professionals Build Advanced Sites Without Programming"
But I have been using these tools long enough to know that that's not 100% accurate, and some of the support techs on here seem perfectly willing to help with some code here and there, which seems to fit with the whole "...without programming" claim.
I was thinking I could do this in PHP using cred_save_data, but I don't know how to check the value of the generic checkbox field. Can you or someone else help me with this?
I have some code from another project I did where the value of one field is changed depending on the value of another field. Can you (or someone else) help me adapt that to use here?
You are right, we do provide some help with custom code. We do that for simple cases, but we don't do it for complex use cases or for repetitive requests. Custom code is still out of the scope of support.
Regarding your case, you should probably try this:
Keep in mind that this will work only for the form with ID 69, otherwise, you should adapt the first line to the form's ID. if it is 1234, then change the first line to:
If this does not help, allow me temporary access to your website to check this further. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
Please let me know:
- A URL on the frontend where we can see the form.
- The URL of the form on the backend.
- The URL on the backend where we can see this custom code. Or FTP access if it is being added to the theme's functions.php file.