Forum

Thread tagged as: Error, Api, Add-on-development

API - template - field ID

Hello,

I'm using the API to develop an add-on. When using a template to define a field, it would appear that the field ID is being prefixed with "perch_" (which is my PERCH_DB_PREFIX).

So, my template includes:

<perch:league id="notes" label="Notes" type="textarea" textile="true" size="s autowidth" />

My blah.post.php includes:

$Form->fields_from_template

Looking at "view source", I see:

<textarea id="perch_notes" name="perch_notes" ...

When then using:

$postvars = array('longname', 'shortname', 'prefix', 'suffix', 'notes');
$data = $Form->receive($postvars);

I'm obviously not seeing the data from the "notes" field. Because it's called "perch_notes"... I can't see anything in the API docs about this - am I missing something or is this a bug?

Perch Runway 2.8.8.

Cheers.

Duncan Revell

Duncan Revell 78 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Perch manages the field names to avoid conflicts. This is how you can edit multiple items on one page and add extra items to repeaters and blocks without getting field name conflicts.

If your field is in the template rather than statically added to the form, $Form->receive is too low-level. You need to move up to a higher abstraction level:

$data = $Form->receive_from_template_fields($Template, $previous_values, $Things, $Thing);

Using the sample app terminology:

  1. $Template is a PerchAPI_Template object, instantiated with your template.

  2. $previous_values is an associative array of the stored data (for editing and detecting changes)

  3. $Things is a Thing factory object, from a class that inherits PerchAPI_Factory

  4. $Thing is the object you're editing (or it can be false), from a class that inherits PerchAPI_Base

Apologies for the current state of the API docs - they do need some work. The latest Sample App is more up to date than the docs are at this point.

Duncan Revell

Duncan Revell 78 points
Registered Developer

Ah, OK. That makes sense - I was deviating away a bit from the examples. I was also using the Sample app v2, I think - I'll have a look at the latest one.

Cheers.