If your form is creating a post, and the YouTube url form field will populate a custom field for the post, you might try something like this:
- Using the form editor, create a "Custom Field" (found among the "Post Fields").
- Under this new field's Properties tab, select "Website" from the "Field Type" dropdown. Now this field will undergo validation as url, possibly first by the browser due to the HTML5 setting Richard mentioned, but then because GFFormDisplay::validate() (in form_display.php) will see that this field's inputType is 'website' and will thus check GFCommon::is_valid_url() (in common.php).
- Then, select your "Custom Field Name" (still under the "Properties" tab). With the "Existing" radio button checked, this dropdown should include the name of your youtube url custom field, so long as you've previously saved at least one post with a value for that custom field (otherwise the custom field appears nowhere in the wp_postmeta table, whose meta_key entries are used to populate the "Custom Field Name" list). Or, perhaps you could choose the "New" radio button, if that approach better suits your needs.
If you weren't intending to save the field value to a post's custom field, you may still find you could use a regular website field (not necessarily the "Custom Field" of website inputType), just to benefit from the related validation, then use the gform_after_submission hook to grab the field value and perform whatever actions you wish.
Posted 6 years ago on Saturday July 6, 2013 | Permalink