• Resolved EmilianoD85

    (@emildebski)


    Hi there.

    Thanks for a great plugin first of all.

    I’m building a real estate webpage for a client, and want to put a mortgage calculator on each post (property) – i’m looking to populate the first field in my form (a “price” field) automatically/dynamically, by fething the property price (which is stored on each post in a advanced custom field), so the user don’t have to do it by themselves every time they are looking at a new property post.

    How do i do that?

Viewing 12 replies - 1 through 12 (of 12 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @emildebski

    If you are integrating the forms in the pages of properties directly through the template file of the theme active on your website, and the field in the form for the price is the fieldname1, and the form’s id is 3, you can insert a piece of code similar to the following into the template file:

    
    <SCRIPT>
    cpcff_default = { 1 : {} };
    cpcff_default[1][ 'fieldname1' ] = 10.30;
    </script>
    <?php print do_shortcode('[CP_CALCULATED_FIELDS id="3"]'); ?>
    

    Of course, replacing the 10.30 with the property price, obtained with the WordPress functions.

    More information in the following link:
    https://cff.dwbooster.com/documentation#populate-form

    Another alternative would be using the set of “DS” fields: Using the information stored in a database or csv file in the form

    However, as the “DS” fields are distributed with the Developer and Platinum versions of the plugin, we are not allowed to support any customers in these forums.

    For pro or commercial product support please contact us directly on our site. This includes any pre-sales topics as well.

    Commercial products are not supported in these forums. We will happily answer this and any other questions you can have on our own site.

    Thank you.

    Thread Starter EmilianoD85

    (@emildebski)

    Thanks for the quick reply.

    I’m not quite sure i understand correctly in regards of the “10.30” part.

    The price of a property, is stored in a custom field named “price” under each post/property, and is not static but changes on each property as the prices are obviously different. So i need your script to fetch the value of that field.

    Plugin Author codepeople

    (@codepeople)

    Hello @emildebski

    The function you need is not part of our plugin. If you prefer to use the first method described in my previous entry, and you want to get the a custom field associated to a post (the custom fields are usually associated to the post as a metadata), you should use the WordPress function: get_post_meta

    Best regards.

    Thread Starter EmilianoD85

    (@emildebski)

    Something like this then – in prolongation of your example (my ACF name for price is “pris”):

    <SCRIPT>
    cpcff_default = { 1 : {} };
    cpcff_default[1][ ‘fieldname1′ ] = <?php echo get_post_meta(get_the_ID(),’pris’,true); ?>;
    </script>
    <?php print do_shortcode(‘[CP_CALCULATED_FIELDS id=”3″]’); ?>
    </SCRIPT>

    Plugin Author codepeople

    (@codepeople)

    Hello @emildebski

    The shortcode must be inserted after closing the script tag:

    
    <script>
    cpcff_default = { 1 : {} };
    cpcff_default[1]['fieldname1'] = '<?php echo get_post_meta(get_the_ID(),'pris',true); ?>';
    </script>
    <?php print do_shortcode('[CP_CALCULATED_FIELDS id="3"]'); ?>
    

    Be sure there is a fieldname1 field in the form.
    Best regards.

    Thread Starter EmilianoD85

    (@emildebski)

    Thanks for the quick reply. Will try it out now. Does it matter which type of field “fieldname1” is? Can it be a currency field, which will give users the ability to change the pre-populated amount on the frontend, to try different pricing/mortgage calculations?

    Plugin Author codepeople

    (@codepeople)

    Hello @emildebski

    Yes, it can be a currency field.

    Best regards.

    Thread Starter EmilianoD85

    (@emildebski)

    Hmmm did not work for me.

    This is my code:

    <script>
    cpcff_default = { 1 : {} };
    cpcff_default[1]['fieldname3'] = '<?php echo get_post_meta(get_the_ID(),'pris',true); ?>';
    </script>

    I created a test form, with only 1 field (currency) = fieldname3.

    And inserted the form via text shortcode (not php) = [CP_CALCULATED_FIELDS id=”6″].

    I see the form on the frontend, but the currency field is empty.

    Plugin Author codepeople

    (@codepeople)

    Hello @emildebski

    Please, share the URL to the page where the form and code were inserted.

    Best regards.

    Thread Starter EmilianoD85

    (@emildebski)

    Plugin Author codepeople

    (@codepeople)

    Hello @emildebski

    If you are using a piece of PHP code, it should be inserted into the template file of the theme active on your website, not in the page content, or the PHP code won’t be evaluated. Please, look the screenshot below (as you can see the PHP is not being evaluated):

    Best regards.

    Thread Starter EmilianoD85

    (@emildebski)

    Works now! Thanks so much. Had to put the js code in footer – don’t knwo why it didn’t work inside of the html/template.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Dynamically populate a field with value from a ACF’ is closed to new replies.