PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

HTML and PHP manipulation in post

  1. Hey there,

    I am trying to have gravity forms automatically do some things for me when creating a new post.
    I have two fields involved in this problem. The first one is the post body which is coming through just fine. The second one is a custom field I inserted into the form for a youtube video URL. I want to do a couple things with this URL.

    The URL looks like this: http://youtu.be/gukwO4uCgTY
    This is the ID of the video in the URL above: gukwO4uCgTY

    I want to take the URL and pull only the ID out of it.
    Then I want the following code to be inserted into the post in a way thats invisible to the user, and have that ID inserted where indicated below (between the slashes).

    <a href="
    <?php get_permalink(); ?>
    ">
    <img alt="" src="http://img.youtube.com/vi/********INSERT_ID_HERE***********/2.jpg" title="Test Image" class="alignnone" width="120" height="90" />

    Is there a way to pass PHP and HTML in to the body of the post or the template?

    Posted 12 years ago on Tuesday September 4, 2012 | Permalink
  2. For part one, to strip the video ID, see this:
    http://www.gravityhelp.com/forums/topic/youtube-video-url-converted-to-youtube-embed-code#post-68832

    For part two, if you want to use PHP there, you will need to add that to your page template, since PHP will not be parsed in the post body by default. If you can get around the PHP requirement (what is the permalink to? The current post, in the current post?) then you can add all this to your content template. HTML is supported in the content template, but PHP would not be executed by WordPress.

    Posted 12 years ago on Wednesday September 5, 2012 | Permalink
  3. Chris,

    Im ok with figuring out the code to pull the ID out of the URL etc, the part I am lost in is how to even access the data that goes into my post.

    I am trying to use the $entry variable within the my content.php file. Is it even accessible there? Or do I need to access this $entry variable in one of the plugin PHP files.

    Can I get access to the submission data so I can use it in a template file somehow, with a DB query or something of the like?

    I need to use the submitted you tube URL to create a URL based thumbnail on the blog roll and then use that same URL to make an embedded video appear on the single posts pages.

    Lastly, this has been giving me quite the headache for a couple days now. Is there someone you could refer me to that could help me out with this? I would be able to pay for a few hours of time, but I would prefer that the resource be intimately familiar with the gravity forms plugin so I am not paying for someone to learn about it.

    Posted 12 years ago on Wednesday September 5, 2012 | Permalink
  4. You can post a job on our job board and find someone familiar with Gravity Forms.
    http://www.gravityhelp.com/forums/forum/job-board

    The $entry object will not be accessible to your content.php template file unless you send it there. You did not mention this in your first post. What is it that you're trying to access in the template?

    I think if we have a clearer picture of what you're trying to do, we'll be able to help you. What part of the $entry do you need?

    I explained to someone recently how to access the complete $entry object in a page template by passing the entry ID to the template, then pulling the information out of the entry. http://www.gravityhelp.com/forums/topic/confirmation-page-shortcodes#post-72801

    Posted 12 years ago on Wednesday September 5, 2012 | Permalink
  5. I have been playing around with this code for a while just trying to get something to appear on screen. Its pretty sloppy but here goes:

    <?php $lead = RGFormsModel::get_lead($lead_id); ?> // tried with lead_id and entry_id here in the get_lead function
    <?php echo $lead[8]; ?> // a drop down menu
    <?php print $lead[6]; ?> // the you tube url entry
    <?php print("hello"); ?> // just to make sure i wasnt going insane, this is working
    <?php if ($lead[8] == "Video"): ?>
    <?php $YT_URL_ARRAY = array(); ?>
    <?php $YT_URL_ARRAY = explode( '/', $lead[6] ); ?>
    <?php $YT_URL_ID = $YT_URL_ARRAY[1]; ?>
    <?php print $YT_URL_ID; ?>
    <?php endif; ?>

    Once I get the ID extracted from the URL with above code then I will be inserting it into this code on my content.php template:

    // permalink is a wordpress function for the post's link
    <img src="http://img.youtube.com/vi/ID_WOULD_GO_HERE/2.jpg" /> // some php would go in there to insert the ID so I could pull the you tube video's thumbnail for use on the blog roll

    THEN on the content-single.php (the single post page) I would want to pull the ID out of the form submitted URL again and insert it into this code:

    <iframe width="560" height="315" src="http://www.youtube.com/embed/ID_WOULD_GO_HERE" frameborder="0" allowfullscreen></iframe> // an embedded youtube video

    Basically I am trying to get the ID so I can use it to request a thumbnail of the video's image to be used on the blog roll post snippets. Then I want to have the embedded video on the full size page.

    I am trying to mirror something like the videos page here: http://www.dorkly.com/videos

    Posted 12 years ago on Wednesday September 5, 2012 | Permalink
  6. The code that was trimmed was just an anchor tag that would be wrapped around the image linking to the single post page of the post in question, not that important

    Posted 12 years ago on Wednesday September 5, 2012 | Permalink