Post title as field value
-
Hi, is it possible to get the title of a specific post with a script in the HTML field?
Thank you
-
Hello @luciche
Yes, of course. For example, assuming you want to get the label of the fieldname1 field, you can use the following piece of code as part of the script into the “HTML Content” field:
jQuery('[class*="fieldname1_"]>label').text();Best regards.
What I mean is to insert the name of a specific post (example post-99) as a value into a hidden field (fieldname10).
Hello @luciche
I’m sorry, my mistake.
The simplest solution is:
The plugin transforms the extra attributes in the forms’ shortcode into global javascript variables with the same values of the attributes.
So, assuming the id of the form is 1, you can insert the shortcode as follows:
[CP_CALCULATED_FIELDS id="1" post_var="post-99"]and then, insert a calculated field in the form, that you can configure as hidden by ticking a checkbox in its settings, and enter the variable name as its equation:
post_varBest regards.
I’ve made both fields
The HTML field https://ibb.co/J7WwL27
Calculated field https://ibb.co/8cstfVMand I want to insert the post title in this equation
https://ibb.co/jDwQcHpRight now it uses fieldname23, which is a hidden field with manual added value, and when I change it with the new fieldname25 it doesn’t calculate.
What am I doing wrong?
Hello @luciche
The shortcodes are used to insert the forms on pages. You cannot insert the form’s shortcode into the same form, that’s incorrect.
Please, look at top of your own screenshot (https://ibb.co/J7WwL27). The shortcode of your form is:
[CP_CALCULATED_FIELDS id="12"]So, if you want to insert the form into the post 8331, enter into the post’s content, the shortcode:
[CP_CALCULATED_FIELDS id="12" post_var="post-8331"]The equation of the fieldname25 field would be fine.
Best regards.
Understood.
I’ve removed the HTML field, I’ve left only the calculated field (fieldname25 https://ibb.co/DfdQnQF), replaced the fieldname23 with fieldname25 in the equation(function(){ var v = fieldname2*((fieldname16 == 'Euro') ? fieldname25 : 1); if(v <= 100) return 0; if(v <= 7000) return PREC(150*1.19, 0); if(v <= 15000) return PREC((v*.022)*1.19, 0); if(v <= 30000) return PREC(((v-15001)*.016+330)*1.19, 0); if(v <= 60000) return PREC(((v-30001)*.013+580)*1.19, 0); if(v <= 300000) return PREC(((v-60001)*.009+970)*1.19, 0); if(v <= 600000) return PREC(((v-300001)*.0065+3130)*1.19, 0); return PREC(((v-600001)*.0044+5080)*1.19, 0); })()and added the shortcode
[CP_CALCULATED_FIELDS id="12" post_var="post-8331"]into a page but it doesn’t calculate.
I’m adding the shortcode in another page, not 8331.
What am I missing?
Thank youHello @luciche
After the modifications the value of the fieldname25 field would be the text:
post-8331, and you cannot use a text into a mathematical operation like:var v = fieldname2*((fieldname16 == 'Euro') ? fieldname25 : 1);Best regards.
The title of the post-8331 is a number (4.8408), not text
https://tinyurl.com/ybl7acobHello @luciche
In this case, you should pass the value directly through the shortcode:
[CP_CALCULATED_FIELDS id="12" post_var="4.8408"]Best regards.
The reason why I want to insert the page name, and not just a number, is that the page name changes daily automatically (exchange rate scraper)
Hello @luciche
What is for you the page’s name? Is it a class name assigned to a tag in the web page? How is the value included in the tag, as its text or as an attribute?
Please, send me the link to the page.
Best regards.
https://tinyurl.com/ybl7acob
it’s the entry title H1Hello @luciche
With your page’s structure you don’t need pass any additional attribute to the form. Simply edit the equation associated to the fieldname25 field as follows:
jQuery('.entry-title').text()Best regards.
Added https://ibb.co/2jJYrGq but nothing.
As mentioned, the title is in a different post than the one with the form.
The title is in post-8331 and the form is in post-1086Hello @luciche
The URL you sent me as reference does not include the form:
Please, send me the link to a page where are inserted both: the form and the title.
Best regards.
The topic ‘Post title as field value’ is closed to new replies.