Hello @keyspan
If you define a new attribute in the form’s shortcode, it would be transformed into a javascript variable with global scope.
For example, assuming you want to populate the fieldname1 with the value of attribute: my_var defined through the shortcode:
[CP_CALCULATED_FIELDS id="1" my_var="43"]
The previous shortcode insert the form with id=”1″ in the page, and will generate a javascript variable called my_var whose value is the number 43
Now, in the form, insert a “HTML Content” field with the following piece of code as its content to assign the value of the my_var variable to the fieldname1 after the form be generated:
<script>
fbuilderjQuery(document).one('showHideDepEvent', function(){
fbuilderjQuery('[id*="fieldname1_"]').val(my_var).change();
});
</script>
and that’s all. Of course, the way you extract the value from the custom field associated to the post to be used in the shortcode, won’t be part of our plugin.
Second alternative:
There is a second alternative that not requires to define a new attribute into the shortcode. In this case you should to include a block of javascript code into the content of same page that includes the form, to define the default values of form’s fields. Following the same example above:
<SCRIPT>
cpcff_default = { 1 : {} };
cpcff_default[1][ 'fieldname1' ] = 43;
</SCRIPT>
Note: Remember in this case the block of code is inserted directly into the page’s content.
Similar to the previous case, the way you replace the number 43 in the piece of code above by the corresponding “Advance Custom Field” value should be managed by yourself in this case.
More information in the following link:
https://cff.dwbooster.com/documentation#populate-form
My preferred solution:
My preferred solution allows the form to read the information of the custom fields directly from the database, the form, simply should know the post where it was inseted.
This solution requires the use of DS fields distributed with the Developer and Platinum versions of the plugin. DS is a set of fields whose values are read from an external data source, like a database or CSV file (Number DS, Currency DS, Line Text DS, and so on).
The “Advanced Custom Fields” plugin stores the values of variables into the WordPress database’s table: wp_postmeta, entering into the column post_id the id of the post where the field is defined, into the meta_key column the field’s name, for example: event_title and into the meta_value column, the value assigned to the field in the corresponding post.
So, the process would be as follows:
Pass the post id into the form’s shortcode:
[CP_CALCULATED_FIELDS id="1" post_id="123"]
and then, insert a “Line Text DS” field (or the DS field that you prefer) into the form, with the following database query:
SELECT meta_value as value FROM {wpdb.postmeta} WHERE meta_key='event_title' AND post_id=<%post_id%>
The queries for the other Advance Custom Fields would be:
SELECT meta_value as value FROM {wpdb.postmeta} WHERE meta_key='event_price' AND post_id=<%post_id%>
and
SELECT meta_value as value FROM {wpdb.postmeta} WHERE meta_key='event_date' AND post_id=<%post_id%>
More information in the following link:
https://cff.dwbooster.com/blog/2019/02/14/ds/?index=1
Best regards.