lisardo
lisardo

Reputation: 1454

Powermail: create fields from entries in database

My problem:

i need a matrix of fields in Powermail:

product_1 - price_1 - number_1
product_2 - price_2 - number_2
product_3 - price_3 - number_3

and so on. No problem to create this fields manually, but i need it derived from a database. The numbers of lines depends on the number of entries in the database.

is there a possibility to create fields "on the fly", perhaps by typoscript or a userfunc?

Thanks!

Upvotes: 0

Views: 711

Answers (2)

Alex Kellner
Alex Kellner

Reputation: 1299

I would create a new field type an call it (e.g.) productsheet. In the manual there is an example how to do it: https://docs.typo3.org/typo3cms/extensions/powermail/ForDevelopers/AddNewFields/Index.html

Here two example page TSConfig lines for the new field:

# Add new fields
tx_powermail.flexForm.type.addFieldOptions.productsheet = Product Fields
tx_powermail.flexForm.type.addFieldOptions.productsheet.dataType = 1

Here is an example Productsheet.html partial file for this:

{namespace vh=In2code\Powermail\ViewHelpers}

<h2><vh:string.escapeLabels>{field.title}</vh:string.escapeLabels><f:if condition="{field.mandatory}"><span class="mandatory">*</span></f:if></h2>

<table>
	<thead>
	<tr>
		<th scope="col">Menge</th>
		<th scope="col">Artikel Nr.</th>
		<th scope="col">Bezeichnung</th>
		<th scope="col">Preis Fr./m</th>
	</tr>
	</thead>
	<tbody>

	<f:for each="{0:1,1:2,2:3,3:4,4:5,5:6,6:7,7:8,8:9,9:10}" as="key">
		<tr>
			<td>
				<f:form.textfield type="number" class="mdl-textfield__input " name="field[{field.marker}][amount_{key}]" value="" />
			</td>
			<td>
				<f:form.textfield class="mdl-textfield__input " name="field[{field.marker}][article_no_{key}]" value="" />
			</td>
			<td>
				<f:form.textfield class="mdl-textfield__input " name="field[{field.marker}][description_{key}]" value="" />
			</td>
			<td>
				<f:form.textfield class="mdl-textfield__input " name="field[{field.marker}][price_{key}]" value="" />
			</td>
		</tr>
	</f:for>
	</tbody>
</table>

Next step would be to insert fields - as you wrote - on the fly. So what about inserting an own viewhelper instead of defining a hardcoded array in the Now you could prefill the fields with value="" by your own.

Hope that helps

Upvotes: 1

Ren&#233; Pflamm
Ren&#233; Pflamm

Reputation: 3354

You can use the TypoScript field of powermail to generate code from typoscript.

You can also use your own field type like discribed here with page TSConfig:

tx_powermail.flexForm.type.addFieldOptions.new = New Field

# The label could also be written with LLL: to localize the label
# Example to grab a value from locallang.xml or locallang.xlf
#tx_powermail.flexForm.type.addFieldOptions.new = LLL:EXT:ext/Resources/Private/Language/locallang.xlf:label

# Tell powermail that the new fieldtype will transmit anything else then a string (0:string, 1:array, 2:date, 3:file)
# Example for dataType array
#tx_powermail.flexForm.type.addFieldOptions.new.dataType = 1

# The new field is not just a "show some text" field. It's a field where the user can send values and powermail stores the values?
# You can tell powermail that this new field should be exportable in backend module and via CommandController
#tx_powermail.flexForm.type.addFieldOptions.new.export = 1

newis the field identifier. Powermail search by default for a partial with the identifier name e.g. New.html.

Now you can use a ViewHelper to get the data and create the html for the fields.

Upvotes: 0

Related Questions