Gravity Forms: automatically populating fields by getting the data of a YouTube
-
I am using Gravity Forms on my WordPress website where people can share videos, and I want the title, description, etc. to be populated automatically by getting the data from the YouTube video. After browsing Google for a couple of hours, I can’t seem to get it to work. (I have 0 experience in php)
All I was able to do is get the video ID from the URL by using this code:
add_filter("gform_save_field_value", "save_field_value", 10, 4); function save_field_value($value, $lead, $field, $form){ //if not the form with fields to encode, just return the unaltered value without checking the fields if(absint($form["id"]) <> 1) /* If the form is not ID 1 */ return $value; //array of field ids to encode $encode_fields = array(2); /* Field 2 is the video URL from which we need the video ID */ parse_str( parse_url( $value, PHP_URL_QUERY ), $my_array_of_vars ); //see if the current field id is in the array of fields to encode; encode if so, otherwise return unaltered value if(in_array($field["id"],$encode_fields)) return $my_array_of_vars['v']; /* Return the video ID i.e. the value after '&v=' */ else return $value; }
I also found this to get the data from the video: https://stackoverflow.com/questions/10896233/how-can-i-retrieve-youtube-video-details-from-video-url-using-php
Hope someone can help me, thanks!
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Gravity Forms: automatically populating fields by getting the data of a YouTube’ is closed to new replies.