Remove empty fields from print friendly display? - Shylock - Oct 13th, 2010
Hi All
I have a form that includes 12 identical rows of three columns (item name, quantity and type).
The user is only required to fill in the first row.
Is there a way to remove the empty rows from the print friendly display if a user only uses say three rows?
At the moment all 12 rows are shown even if no entry was made on some rows of the form.
Thanks
Tim
RE: Remove empty fields from print friendly display? - Ben - Oct 17th, 2010
Hi Tim,
Excellent question! Sure, this can be done - but in all honesty, it's not the most obvious thing in the world.
The Export Manager module handles all the markup generation - i.e the HTML, XML, CSV etc. formats in which form content is downloadable / viewable. So to do what you need, you'll need to create a new "Export Type" for the HTML/Printer-friendly group. Here's how to do it:
1. Go to your Modules page,
2. Select the Export Manager module,
3. Edit the HTML / Printer-friendly Export Group,
4. Click on the Export Types tab,
5. Click the "Add Export Type" button. On the following page, enter the following values into the fields:
Export type name: Non-empty fields only
Filename: submissions-{$M}.{$j}.html
Smarty content:
Code: <h1>{$form_name}</h1>
{* loop through all submissions in the current result set *}
{foreach from=$submissions item=submission name=row}
<table cellpadding="2" cellspacing="0" width="100%" class="print_table">
{* loop through all fields in the current View *}
{foreach from=$display_fields item=field name=col_row}
{assign var=field_id value=$field.field_id}
{assign var=field_type value=$field.field_info.field_type}
{assign var=col_name value=$field.col_name}
{assign var=value value=$submission.$col_name}
{if $value != ""}
<tr>
<th width="140">{$field.field_title}</th>
<td>
{if $field_type == "select" || $field_type == "radio-buttons"}
{smart_display_field_values field_id=$field_id selected=$value}
{elseif $field_type == "checkboxes" || $field_type == "multi-select"}
{smart_display_field_values field_id=$field_id selected=$value multiple=true}
{elseif $field_type == "system"}
{if $col_name == "submission_id"}
{$submission.submission_id}
{elseif $col_name == "submission_date"}
{$submission.submission_date|custom_format_date:$timezone_offset:$date_format}
{elseif $col_name == "last_modified_date"}
{$submission.last_modified_date|custom_format_date:$timezone_offset:$date_format}
{elseif $col_name == "ip_address"}
{$submission.ip_address}
{/if}
{elseif $field_type == "textarea"}
{$value|nl2br}
{else}
{$value}
{/if}
</td>
</tr>
{/if}
{/foreach}
</table>
<br />
{/foreach}
All I did in this code was wrap the output in a test: if the line is empty, don't output anything - not even the label.
Then, go back to your form in Form Tools and view the submissions. At the bottom of the page, in the dropdown for the HTML/Printer-Friendly option, you should see your new "Non-empty fields only" option. Select it and click "display".
Hope this helps!
- Ben
RE: Remove empty fields from print friendly display? - Shylock - Oct 18th, 2010
Thank you Ben for your fantastic support I shall try that today!
Best regards
Tim
Update: Thanks that is perfect. Incredibly powerful feature.
RE: Remove empty fields from print friendly display? - VidalFranco - Jul 15th, 2014
(Oct 17th, 2010, 4:42 AM)Ben Wrote: Hi Tim,
Excellent question! Sure, this can be done - but in all honesty, it's not the most obvious thing in the world.
The Export Manager module handles all the markup generation - i.e the HTML, XML, CSV etc. formats in which form content is downloadable / viewable. So to do what you need, you'll need to create a new "Export Type" for the HTML/Printer-friendly group. Here's how to do it:
1. Go to your Modules page,
2. Select the Export Manager module,
3. Edit the HTML / Printer-friendly Export Group,
4. Click on the Export Types tab,
5. Click the "Add Export Type" button. On the following page, enter the following values into the fields:
Export type name: Non-empty fields only
Filename: submissions-{$M}.{$j}.html
Smarty content:
Code: <h1>{$form_name}</h1>
{* loop through all submissions in the current result set *}
{foreach from=$submissions item=submission name=row}
<table cellpadding="2" cellspacing="0" width="100%" class="print_table">
{* loop through all fields in the current View *}
{foreach from=$display_fields item=field name=col_row}
{assign var=field_id value=$field.field_id}
{assign var=field_type value=$field.field_info.field_type}
{assign var=col_name value=$field.col_name}
{assign var=value value=$submission.$col_name}
{if $value != ""}
<tr>
<th width="140">{$field.field_title}</th>
<td>
{if $field_type == "select" || $field_type == "radio-buttons"}
{smart_display_field_values field_id=$field_id selected=$value}
{elseif $field_type == "checkboxes" || $field_type == "multi-select"}
{smart_display_field_values field_id=$field_id selected=$value multiple=true}
{elseif $field_type == "system"}
{if $col_name == "submission_id"}
{$submission.submission_id}
{elseif $col_name == "submission_date"}
{$submission.submission_date|custom_format_date:$timezone_offset:$date_format}
{elseif $col_name == "last_modified_date"}
{$submission.last_modified_date|custom_format_date:$timezone_offset:$date_format}
{elseif $col_name == "ip_address"}
{$submission.ip_address}
{/if}
{elseif $field_type == "textarea"}
{$value|nl2br}
{else}
{$value}
{/if}
</td>
</tr>
{/if}
{/foreach}
</table>
<br />
{/foreach}
All I did in this code was wrap the output in a test: if the line is empty, don't output anything - not even the label.
Then, go back to your form in Form Tools and view the submissions. At the bottom of the page, in the dropdown for the HTML/Printer-Friendly option, you should see your new "Non-empty fields only" option. Select it and click "display".
Hope this helps!
- Ben
Hi Ben,
I have the same question as above. I have followed your steps and when i display the page its blank!! please help. I have over 100 fields and will only like to do a print friendly HTML of what is field out or checked. I have spent numerous hours and unable to get it to work. Thank You!!
RE: Remove empty fields from print friendly display? - enginama - Dec 20th, 2016
I also found this code not working.
I took the main if statement and applied it to the standard template in export manager as below, all I added was the '{if $value!= ""}' & {/if}'
Hope this explanation helps someone.[/code]
Code: <h1>{$form_name} - {$view_name}</h1>
{foreach from=$submissions item=submission name=row}
{assign var=submission_id value=$submission.submission_id}
<table cellpadding="2" cellspacing="0" width="100%"
class="print_table one_item">
{foreach from=$display_fields item=field_info}
{assign var=col_name value=$field_info.col_name}
{assign var=value value=$submission.$col_name}
{if $value != ""}
<tr>
<th width="140">{$field_info.field_title}</th>
<td>
{smart_display_field form_id=$form_id view_id=$view_id
submission_id=$submission_id field_info=$field_info
field_types=$field_types settings=$settings value=$value}
</td>
</tr>
{/if}
{/foreach}
</table>
{if !$smarty.foreach.row.last}
<div class="no_print"><i>- {$LANG.phrase_new_page} -</i></div>
<br class="page_break" />
{/if}
{/foreach}
|