Filter Gravity Forms Input before saving
I share some tips on Gravity forms about how to save Gravity Forms Advanced Field to Custom Meta Field and this time I would like to share how to filter the inputs from Gravity Forms before saving to your database.
For my use case I would like to remove the ‘http://’ from the url field, so that all the url that inputs by the user will be standardize , the same tips can be use if you need to apply some filtering for any input before you actually save it, for example, you might want to remove the dollar sign ($) on a pricing input.
Example I have created this url field on the forms, you can see that the default placeholder for url field will be ‘http://’ , some of the user understand this, so that they might just put in their url without the ‘http://’, some user might not be understood, once they enter the field, the ‘http://’ is disappear , they might think they need to input the ‘http://’ in front of their url input, which is why this looks a bit confusing.
The easy to solve this is either add some validation JavaScript on the form or doing a backend filter on the input, , what I mean for backend filter is i will do a string replace on every url input, just to ensure all the url will be without ‘http://’.
Just added this code in the functions.php, the action is gform_pre_submission_1 where the 1 will be your form id, the input id for the POST parameter will the Field ID, added in a simple string replace function to ensure the ‘http://’ will be replace.
Hopefully this tips help, let me know if you handle situation like this differently.