• Resolved zxpw

    (@zxpw)


    I have a form that contains a field for users to input a number as well as two dropdowns. I would like to be able to set this field to a number of my choosing when I insert the form into my blog posts via shortcode. This would save my readers having to manually enter the relevant number themselves. It would also be great if I could choose the dropdown defaults as well.

    Apologies if this has already been answered before. I could not find a solution in the forum or documentation. Thanks.

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

    (@codepeople)

    Hello @zxpw

    Yes, that’s possible. The plugin transforms every additional attribute in the form shortcode into javascript variables with global scope. Ex.

    [CP_CALCULATED_FIELDS id="1" first_attr="123" second_attr="option A" third_attr="another value"]

    The attributes’ names were chosen at random, just to describe the process.

    Now, assuming the number and dropdown fields are fieldname1, fieldname2, and fieldname3, you can insert a calculated field in the form as an auxiliary (you can hide by ticking a checkbox in its settings), and enter the following equation:

    (function(){
    if('first_attr' in window) getField(fieldname1|n).setVal(first_attr);
    
    if('second_attr' in window) getField(fieldname2|n).setVal(second_attr);
    
    if('third_attr' in window) getField(fieldname3|n).setVal(third_attr);
    })()

    Please, note the use of the |n modifier in the equation. The plugin replaces fields’ names with their values before evaluating the equations. The |n modifier tells the plugin you are referring to the fields’ names directly instead of their values.

    Best regards.

    Thread Starter zxpw

    (@zxpw)

    That worked perfectly. Thank you so much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can I populate certain fields of a form in the shortcode?’ is closed to new replies.