ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

{exp:safecracker} custom file field true-false testing failure

February 22, 2012 5:05am

Subscribe [1]
  • #1 / Feb 22, 2012 5:05am

    mark186282

    290 posts

    I’m experiencing an odd bug in a safecracker:

    The specific field I’m testing is a Safecracker File custom field (that I am filling with images only)

    I thought that this may be related to the File field variable pair bug, but I have implemented the bug repair and the problem persists.  (Same is true with the File Upload Prefs bug)

    For this example, the “account_photo” field contains a photo

    {exp:safecracker
      channel='{zoo_visitor_channel_name}'
      entry_id='{zoo_visitor_id}'
      include_jquery="no"
      safecracker_head="yes"
      preserve_checkboxes="yes"}
     
      {if account_photo}
      PHOTO IS GOOD
    
      {field:account_photo}
      {if:else}
      NO PHOTO
    
      {field:account_photo}
      {/if}
      
     {/exp:safecracker}

    The result of the above: “NO PHOTO”

    {exp:safecracker
      channel='{zoo_visitor_channel_name}'
      entry_id='{zoo_visitor_id}'
      include_jquery="no"
      safecracker_head="yes"
      preserve_checkboxes="yes"}
     
      {account_photo}
    
      
      {if account_photo}
      PHOTO IS GOOD
    
      {field:account_photo}
      {if:else}
      NO PHOTO
    
      {field:account_photo}
      {/if}
      
     {/exp:safecracker}

    The result of above is “PHOTO IS GOOD” (in addition to the output of the {account_photo} variable)

    ...

    Am I testing the presence of content in account_photo correctly?  I also tried {if account_photo != ''} with identical results…

    has anyone else experienced this?

    EE 2.4.0
    MSM

    (perhaps related to this thread?)

    Note that I’ve temporarily patched my situation by adding my custom fields inside HTML comments within the safecracker form:

    <!--
    {account_photo}
    -->
  • #2 / Feb 23, 2012 2:17pm

    Dan Decker

    7338 posts

    Hi mark186282,

    What kind of file field are you using? If you use the SafeCracker File field type, it essentially does this check for you.

    What is your ultimate goal here? I’m happy to help you work out a solution.

    Cheers,

  • #3 / Feb 23, 2012 2:40pm

    mark186282

    290 posts

    Yep, using the safecracker file field

    the safecracker file field has nearly zero configuration options (how to remove a file, how to add a file, etc etc) - I tried to hack the display of the field using css and jquery for quite a while without getting very far at all.

    the goal is to be able to test whether a file has been uploaded for the specific field or not

    1. if it doesn’t exist, we’ll be displaying a specific background image, instructions, etc.
    2. If it does exist, we will be displaying different information.

    With other safecracker fields (including the file field type if I do the above workaround of placing the field content somewhere in the form) - I’m able to do a Boolean test to see if it has content or not.

    The test being performed on the safecracker file field has a bug, in that it always responds false UNLESS I place a {account_photo} tag in my safecracker form.  After I do that, the test for true or false works as we expect.  It appears that the variable is not being initialized properly, and is only initialized if I display the contents of that field.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases