1

I want to change the output of the standard file upload field with something similar to "Whipping File Inputs Into Shape with Bootstrap 3". I am using the following conditional in my Solspace Freeform Pro composer template in an attempt to change the output for file upload field types:

{composer:fields}
{if composer:field_output}
                    {if composer:field_type == 'nonfield_captcha'}
                        {if freeform:captcha}
                                {freeform:captcha}<br />
                                <input type="text" name="captcha" value="" size="20" maxlength="20" style="width:140px;" />
                        {/if}

                     {if:elseif composer:field_type == 'file'}

                          <span class="btn btn-default btn-file">
                              Browse {composer:field_output}
                          </span>

                    {if:else}

                        {composer:field_output}

                    {/if}
                {/if}
{/composer:fields}

The if:elseif field type "file" statement doesn't seem to work in the template and has no effect in the output when the form is rendered:

{if:elseif composer:field_type == "file"}
    <span class="btn btn-default btn-file">
      Browse {composer:field_output}
    </span>
{if:else}
....

enter image description here

To check if there is something wrong with my statement, I changed "file" to "text". The conditional then worked and wrapped all text inputs in the <span> mark-up. So the conditional statement itself appears to work correctly - just not for field_type "file" though.

If there some special statement/conditional that I'm missing to be able to control the output of field_type = "file"?

Version Info:

ExpressionEngine: 2.10.1
Freeform Pro: 4.2.3

1 Answer 1

1

I don't know Composer at all...

This would be comment if it weren't going to be so long.

OK, so let's debug. I'm not sure if this is a production template. If so, holy crap-a-rolla, make a duplicate of the template in question, and set it to only-view-able by Super Admins. Work with that template and leave production alone. If this template is totally in dev-mode, ignore most of this paragraph. The next important part is to set PHP parsing on output for this template.

Next, let's see what we're getting from {composer:field_type}.

{composer:fields}
    {if composer:field_output}
        <?php
        var_dump('{composer:field_type}');
        ?>
    {/if}
{/composer:fields}

What is the outcome of that var_dump() for the fields that you expect to be {composer:field_type} as "file" ?

I've run into many issues where the EE parsing engine ends up outputting a weird value for something like a string like file ... it sometimes ends up as a a string with (made up example):

string(15) "file"

Something seem wrong there :P ? Are there 15 characters in the string file?

Report back and I'll apply some more sleuthing if I can help.

4
  • Thanks for your comment. The thing is - the file type attributes are standard HTML elements (like text, email, password, submit). The element IDs & Names contain the strings but the "type" doesn't. I'll still give your suggestion a go shortly. Thanks
    – Dan
    Sep 27, 2015 at 6:03
  • ... but template tags and EE parsing have everything to do with it's output ... I'd assume they are broken, if anything. My answer/comment was meant to address a possible issue in the parsing engine. Literally the output of the engine to the rendered front-end page is your issue.
    – jrothafer
    Sep 27, 2015 at 7:19
  • 1
    To explain a little further.. you have a conditional that makes programmatic sense, but isn't resolving as such. So there is an issue to overcome; and the EE templating engine has always needed review.
    – jrothafer
    Sep 27, 2015 at 7:23
  • Thanks for the further comms - you were 100% correct. After implementing the snippet, the output of the file type for "file" is actually "file_upload": screencast.com/t/sGx1w1sszHqL
    – Dan
    Sep 27, 2015 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.