Quantcast
Channel: Snippets Archives - Gravity Wiz
Viewing all articles
Browse latest Browse all 196

Set Number of List Field Rows by Field Value

$
0
0
View this code snippet on GitHub.

Found this interesting question on the Gravity Forms forum:

I’m selling tickets. So each ticket needs to be associated with a name/email/etc…

Basically, the user needs a way to gather a set of data per ordered product/ticket. My first instinct was to simply recommend using the List field. The user could specify the number of tickets and then add/remove however many rows they need.

I kept thinking on it and realized it would be really nice if the number of List field rows increased/decreased automatically based on the number of selected tickets. Here’s a snippet to do just that!

How do I install this snippet?

Just copy and paste the snippet above into your theme’s functions.php file.

Do I need to modify this snippet to work with my form?

You just need to create your own instance of the GWAutoListFieldRows class. You’ll find two examples at the bottom of the snippet. Comment them out and then add your own! All you need to set is the $form_id, the $list_field_id, and the HTML id of your input as the $input_html_id property.

Summary

The one piece missing from this snippet is that regardless of how many rows are displayed, none of these rows are actually required. If this functionality is useful, I will dig into this shortcoming and provide a more robust solution.


Viewing all articles
Browse latest Browse all 196

Trending Articles