Get More Out of Gravity Forms
-
Upload
mandi-wise -
Category
Technology
-
view
534 -
download
2
description
Transcript of Get More Out of Gravity Forms
![Page 1: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/1.jpg)
GET MORE OUT OFGRAVITY FORMS
VANCOUVER WORDPRESS MEET-UP – MAY 15, 2014
![Page 2: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/2.jpg)
WHAT WE'LL COVER:1. The challenge
2. Gravity Forms vs. ...
3. Get more out of the box
4. Get more with hooks
5. Some gotchas
![Page 3: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/3.jpg)
THE CHALLENGE
![Page 4: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/4.jpg)
MUST-HAVESA form that would accept user-submitted nominationsand save them as a custom post type
A voting mechanism for each award category that onlyallowed a person to vote once per person per category
![Page 5: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/5.jpg)
SOLUTION?Gravity Forms!
![Page 6: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/6.jpg)
vs.
Single license: $39 Single license: $0 + ???
User analytics: $19File uploads: $39Front-end posting: $39Multi-part forms: $39Conditional logic: $29
TOTAL: $165
![Page 7: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/7.jpg)
OUT OF THE BOX MAGIC
![Page 8: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/8.jpg)
FORM FIELDS IN A SNAP
![Page 9: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/9.jpg)
USER-SUBMITTED POSTS
![Page 10: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/10.jpg)
BUT WHAT ABOUT CPTS?There's a plugin for that.
![Page 11: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/11.jpg)
NEEDED TO TURN THIS...
![Page 12: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/12.jpg)
INTO THIS:
![Page 13: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/13.jpg)
GRAVITY FORMS +CUSTOM POST TYPES
Find it WP plugin directory:wordpress.org/plugins/gravity-forms-custom-post-types/
Better yet, get it from Github*:github.com/bradvin/gravity-forms-custom-post-types
*No PHP error notices with WP DEBUG on.
![Page 14: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/14.jpg)
FORMS IN MODALS (or another modal plugin) will allow you to easilyshow or or hide your form on demand.
Fancybox
![Page 15: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/15.jpg)
IN A THEME FILE
hosted with ❤ by
<div id="voting‐form" style="display:none"> <?php echo do_shortcode( '[gravityform id="6" title="false" description="false" ajax="true"]' ) ?></div><a href="#voting‐form" class="fancybox button">Vote Now</a>
view rawGravity Forms and Fancybox GitHub
Initially hidden form + Ajax submitting= no-fuss modal perfection!
![Page 16: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/16.jpg)
IN THE WILD
![Page 17: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/17.jpg)
IN THE WILD
![Page 18: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/18.jpg)
GET MORE WITH HOOKSAround 200 actions & filters you can use to extend GF...
www.gravityhelp.com/documentation/page/Developer_Docs
![Page 19: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/19.jpg)
WHERE DOES IT GO?1. Your theme's functions.php file
2. A functionality plugin
![Page 20: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/20.jpg)
AUTO-POPULATE FIELDSMany ways to go about this!
gform_field_value_[your custom param]
gform_pre_render_[your form ID]
![Page 21: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/21.jpg)
gform_field_value_[your custom param]
Use this filter for text fields or pre-selection of options in a dropdown, etc. See the offcial docs .here
hosted with ❤ by
function my_city_population_function( $value ){ return 'Vancouver';}add_filter( 'gform_field_value_my_city', 'my_city_population_function' );
view rawDynamically Populate Gravity Forms Text Field GitHub
![Page 22: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/22.jpg)
gform_field_value_[your custom param]
![Page 23: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/23.jpg)
gform_pre_render_[your form ID]
Use this filter to pre-populate choices in a dropdown, etc. See the offcial docs .here
Check out a sample Gist.
![Page 24: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/24.jpg)
CUSTOM VALIDATIONBe the boss of your form AND database!
gform_validation_[your form ID]
![Page 25: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/25.jpg)
gform_validation_[your form ID]
hosted with ❤ by
function my_custom_validation( $validation_result ) { $form = $validation_result["form"]; // Sorry, you don't get to live in Vancouver... if ( $_POST['input_1'] == 'Vancouver' ) { $validation_result["is_valid"] = false; foreach ( $form["fields"] as &$field ) { // NOTE: Replace 1 with the field you would like to validate if ( $field["id"] == "1" ) { $field["failed_validation"] = true; $field["validation_message"] = "Sorry, you can't enter Vancouver here!"; break; } } } // Assign modified $form object back to the validation result $validation_result["form"] = $form; return $validation_result;}add_filter( 'gform_validation_[your form ID]', 'my_custom_validation' );
view rawGravity Forms Custom Validation Example GitHub
See the offcial docs .here
![Page 26: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/26.jpg)
RESTRICT UPLOAD SIZEThere's no way to do this out of the box and you may not
want users uploading 32MB files!
There is a plugin for that, but it's buggy. Instead...Check out this Gist.
![Page 27: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/27.jpg)
CUSTOM CHECK FORDUPLICATES
Preventing duplicates is easy... preventing a single user fromsubmitting the same field value twice is harder.
Check out this Gist.
![Page 28: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/28.jpg)
SOME GOTCHASDuplicate prevention (use )
Ajax and captcha
And on the topic of spam...
this plugin
![Page 29: Get More Out of Gravity Forms](https://reader033.fdocuments.us/reader033/viewer/2022052900/5562d7e0d8b42a6c498b51a0/html5/thumbnails/29.jpg)
THAT'S ALL FOLKS!Find me: and @mandiwise mandiwise.com
All of the snippets: gist.github.com/mandiwise