Can I set a default field value based on a link click outside the form?

By: Kim Rowe | Asked: 04/12/2024
ForumsCategory: How-toCan I set a default field value based on a link click outside the form?
Kim Rowe asked 8 months ago
I am setting up a fundraising page here. At the bottom of this page is a donate form. In the middle of the page are suggested donation amounts ("give $25," "give $50," etc.). Is it possible to have the "your pledge" field show a default value based on clicking one of the "give" links? So clicking "give $25" enters a default value of 25, etc. I found code here, but it's not working or I'm not setting it up correctly.  Thanks in advance if anyone can help me work this out.   
2 Answers
Victor Font answered 8 months ago

You can do this using jQuery. You have monitor the click events for the pledge links then apply the value to the field in your form. You may have a problem with your site. When I was checking your page, you have script files that are not being loaded because of a mismatched mime type. You need to fix that because any js error could prevent jQuery from working.

Kim Rowe replied 8 months ago

Ok, thanks Victor. I'll take a better look.

Rob LeVineRob LeVine replied 8 months ago

I just looked at your website. If you view the source of the page you'll see one lines 437-447 you have script tags that have a PHP script in it. That's no good. Fixing that by moving the PHP code to the server will get rid of one of the major errors in the console.

Kim Rowe answered 8 months ago
Thanks @Victor Font and @Rob LeVine for taking time to comment. I did end up solving this by just using the shortcode [get param="amount"] as the default value in the donation amount field, and forcing the page to reload. I found this somewhere in the Formidable documentation but it took quite a bit of hunting. Here is the live site.

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
crossarrow-right