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.

Hide/Display submitted entry based on whether a file was uploaded or not

  1. This is not a problem - I found a solution. I thought I should share it with the community.

    Goal: provide a webform with a file upload field, and then convert the submitted entry to a Post. In the post, show the uploaded file in a custom download box with a download icon, or if there was no file upload submitted, do not show the download box.

    Solution: Setup 5 fields in the form:
    (1) a Yes/No radio button field for "Upload a File?" set to "No" default;
    (2) a Custom field set to Upload File, with a condition to display if #1 is Yes;
    (3) a Custom Field set to Admin view only with a default value set to "upload" (without the quot marks and no period before it - this is a custom CSS I created in the master style sheet that forms the Download box and icon). This field is set to a condition to display if #1 is "Yes", but since it is an Admin Only field, it doesn't actually display in the form to the user;
    (4) Another Custom Field, same as #3, except with a default value of "hide" (a CSS class set to display:none) and a condition to display with #1 as a "No".
    (5) a Post Body field, set to Admin Only, with Merge tags from other fields, including the following

    <div class="{Admin Only - Hide upload if none selected:26}{Admin Only - Display if file uploaded:27}"><a href="{File upload:20}"><img src="http://mysite.com/wp-content/uploads/textdoc_tn.png" /><span>Download Supporting Documentation</span></a></div><br /><p>[embed]{Post your YouTube link here:23}[/embed]</p>

    The trick: The merge tags above for Custom Fields #3 and #4 are set to insert either the "upload" or "hide" class into the display div class depending on which Yes/No selection is made. Note that the default value in #3 and #4 is just the class name WITHOUT the period in front of it.

    BTW, the [embed] section is a single line text field for users to copy/paste a YouTube URL into it, which publishes it in the post. Even though WP has the embed parsing capabilities built-in, it doesn't work without these shortcode tags added around the merge tag.

    If there is a more poetic way of doing this, please add a comment. I tried a LOT of other solution before this worked!

    Posted 11 years ago on Friday April 5, 2013 | Permalink
  2. Thanks for posting your experience.

    Posted 11 years ago on Wednesday April 10, 2013 | Permalink