Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

User Forms pdf version and email submissions


Reply

8 Posts   2349 Views

Avatar
karibe

5 February 2010 at 3:44am Community Member, 56 Posts

Hello

I'm using that module to receive some pretty complicated polls from the people. When someone will submit such poll we should get completed form
in pdf version as email attachment. What is the simplest way to do that?
As I saw in email body "Spam protection field" is included as "EditableLiteralField77". How to disable it in email body
By contrast "HTML Block" isn't visible in email body but it should.

Avatar
karibe

9 February 2010 at 12:49am (Last edited: 9 February 2010 12:50am), Community Member, 56 Posts

So maybe someone knows how to display in submitted email "HTML Block" content value? As I see in userforms/templates/email/SubmittedFormEmail.ss

<h1>$Subject</h1>
$Body

<% if HideFormData = 1 %>
<% else %>
   <dl>
      <% control Fields %>
         <dt><strong><% if Title %>$Title<% else %>$Name<% end_if %></strong></dt>
         <dd style="margin: 4px 0 14px 0">$Value</dd>
      <% end_control %>
   </dl>
<% end_if %>


dd shows $Value but value for "HTML Block" userforms/code/editor/EditableLiteralField.php is name of the field.
How can I display Field Configuration>HTML content?

Where I find some user forms development resources?

Avatar
Willr

10 February 2010 at 11:37am Forum Moderator, 5511 Posts

but value for "HTML Block" userforms/code/editor/EditableLiteralField.php is name of the field.

It shouldn't be calling $Value on the EditableLiteralField, rather value on the SubmittedFormField object - Does that have the incorrect content? Maybe when saving the form it saves the name rather then the content but I'm pretty sure its not a display issue.

Avatar
karibe

10 February 2010 at 8:43pm Community Member, 56 Posts

Here is the concept.
People are submitting their statements and then when they receive on submitted email a pdf copy, they have to print it, sign it and bring to us.
The problem is that beside common fields like "Text field" I have two that make a problem. Spam protection field which is visible in email as "EditableLiteralField77" and "HTML block". "HTML Block" is used to display some agreement conditions that have to be signed. HTML looks like

<ul>
<li>condition1 </li>
<li>condition2</li>
<li>condition3</li>
<li>condition4</li>
</ul>

Unfortunately In email I see only "Conditions" label.

When I correct that issue next is to attach pdf with form content same as in email:-) As I lookup there is no finished solution, so I'll have to write it myself. Thus maybe You as an module author could prompt me with most elegant method?

Avatar
Willr

10 February 2010 at 8:54pm Forum Moderator, 5511 Posts

Oh right yes, you won't see the HTMLBlock content since the content for it won't actually get submitted in the form (since its readonly, not an editable version - It should actually not even include any htmlblock fields in the email as per how its currently designed but its a bug its showing the title).

If you want to include the content you can define a function getValueFromData() on the form field which will set the value in the email.

So you can either edit the core EditableLiteralField.php (and remember to readd this function when you upgrade) or you can apply the following function as a dataobject decoration

function getValueFromData($data) {
// return the content from the field rather that anything from the data array
return $this->getSetting('Content');
}

Avatar
karibe

10 February 2010 at 10:16pm Community Member, 56 Posts

Works, but html is not parsed:-(

Avatar
karibe

10 February 2010 at 11:45pm (Last edited: 10 February 2010 11:45pm), Community Member, 56 Posts

Problem solved
In pdf attachment issue I've added in UserDefinedForm_EmailRecipient

   static $db = array(
      'EmailAddress' => 'Varchar(200)',
      'EmailSubject' => 'Varchar(200)',
      'EmailFrom' => 'Varchar(200)',
      'EmailBody' => 'Text',
      'SendPlain' => 'Boolean',
      'PdfAttachment' => 'Boolean',
      'HideFormData' => 'Boolean'
   );


and

      $fields = new FieldSet(
         new TextField('EmailSubject', _t('UserDefinedForm.EMAILSUBJECT', 'Email Subject')),
         new TextField('EmailFrom', _t('UserDefinedForm.FROMADDRESS','Send Email From')),
         new TextField('EmailAddress', _t('UserDefinedForm.SENDEMAILTO','Send Email To')),
         new CheckboxField('HideFormData', _t('UserDefinedForm.HIDEFORMDATA', 'Hide Form Data from Email')),
         new CheckboxField('SendPlain', _t('UserDefinedForm.SENDPLAIN', 'Send Email as Plain Text (HTML will be stripped)')),
         new CheckboxField('PdfAttachment', _t('UserDefinedForm.PDFATTACHMENT', 'Add Form Data as PDF attachment')),
         new TextareaField('EmailBody', 'Body')
      );

Now plan is to modify method process in UserDefinedForm_Controller

Avatar
Indika

26 January 2011 at 4:14am Community Member, 3 Posts

if you want to generate pdf , you can use html2pdf library . for more information please read my blog
http://indikagamage.com/blog/how-to-html-to-pdf-in-silverstripe/