Advertisement
chrishajer

Modify content template when no image is uploaded

Sep 27th, 2012
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. <?php
  2. // http://www.gravityhelp.com/forums/topic/make-an-image-a-link-in-post-template
  3. // change the 171 here to your actual form ID
  4. add_action('gform_pre_submission_filter_171', 'change_post_content_template');
  5. function change_post_content_template($form) {
  6.         // if input_5 is submitted, i.e. has an image, then insert the HTML into the content template.  Otherwise, just use {Details:2}
  7.         // check the $_FILES global since it's an image upload
  8.         if ((!isset($_FILES['input_5']['name']) || $_FILES['input_5']['name'] == null)) {
  9.                 $form['postContentTemplate'] = '{Details:2}';
  10.         }
  11.         else {
  12.                 // use a PHP heredoc to preserve line breaks
  13.                 $template = <<<EOT
  14. <a href='{Image:5:large:url}'>{Image:5:listing:right}</a>
  15.  
  16. {Details:2}
  17. EOT;
  18.                 $form['postContentTemplate'] = $template;
  19.         }
  20.         // return the modified form object
  21.         return $form;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement