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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

User Forms pdf version and email submissions


Go to End


8 Posts   3585 Views

Avatar
karibe

Community Member, 56 Posts

5 February 2010 at 3:44am

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

Community Member, 56 Posts

9 February 2010 at 12:49am

Edited: 09/02/2010 12:50am

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

Forum Moderator, 5523 Posts

10 February 2010 at 11:37am

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

Community Member, 56 Posts

10 February 2010 at 8:43pm

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

Forum Moderator, 5523 Posts

10 February 2010 at 8:54pm

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

Community Member, 56 Posts

10 February 2010 at 10:16pm

Works, but html is not parsed:-(

Avatar
karibe

Community Member, 56 Posts

10 February 2010 at 11:45pm

Edited: 10/02/2010 11:45pm

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

Community Member, 3 Posts

26 January 2011 at 4:14am

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/