Using On Page Data to Populate Fields Dynamically

By: Jason Ryan | Asked: 08/06/2022
ForumsCategory: General questionsUsing On Page Data to Populate Fields Dynamically
Jason Ryan asked 2 years ago
Hello - I have a form that is being used in a Product template (so it displays on all Single Product pages) that would allow a User to submit a form to Request a Sample. I am doing this so that I am not creating thousands of forms for all of the Products on the site. Is it possible to somehow do either of the following:
  1. Grab the Page Title to use in the subject line of the email notification being sent
  2. Populate a Dropdown dynamically based on the Product's variations, e.g. Colors
I know the Page Referrer can be included in the base of the email and it is helpful, but would like to pass additional information about the Product that someone is requesting a Sample of. TIA
1 Answers
Best Answer
Victor Font answered 2 years ago
The answer to both questions is yes. You can use jQuery to access a page title and store it in a hidden field on the form. You only need to know the title's ID and retrieve the text using something like this $('#my_hidden_field_id').val( $('#title_id').text() ); Standard dropdowns can be populated dynamically using Formidable's frm_setup_new_fields_vars and frm_setup_edit_fields_vars hooks. If you know where the data you want is stored in the database, you can retrieve it using a SQL SELECT executed through the $wpdb object.
Victor Font replied 2 years ago

Here's an article I wrote in 2014 explaining how to populate a dropdown dynamically:

Jason Ryan replied 2 years ago

Thank you Victor! I will give this a try and let you know. Much appreciated.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community