Jump to content

Getting template specific field properties within the API


wheelmaker24
 Share

Recommended Posts

Hey guys,

I'm trying to build a submit form with the ProcessWire API. After the form is submitted its data should be saved into different pages.

I've followed Soma's great tutorial and wanted to improve it for my use case: Instead of adding every field manually to the form I already managed to automatically read out the fields that belong to a specific template like this:

// Build form
$form = $modules->get("InputfieldForm");
$form->action = "./";
$form->method = "post";
$form->attr("id+name",'$page->name');

// Build fieldset
$fieldset = $modules->get('InputfieldFieldset');
$fieldset->label = 'Personal Data';

// Read out template fields and append them to the fieldset
$registration = $templates->get("registration");
foreach ( $registration->fields as $field )
{
	$field = $field->getInputfield($page);
	$fieldset->append($field);
}

$form->append($fieldset);

// more fieldsets...

// Submit
$submit = $modules->get("InputfieldSubmit");
$submit->attr("value","Anmelden");
$submit->attr("id+name","submit");
$form->append($submit);

This seems to work great – with just one little restriction: Instead of the global field labels I would love to get the template specific settings for each field (defined within the template).

E.g. in this template I'm using a body-Field not labeled as "Body" but as "Description". Same would be great for things like field's columnWidth, required properties and Co.

Is this possible?

Thanks a lot for your help!

Nik

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...