Forum
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.
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:Using the sample app terminology:
$Template
is aPerchAPI_Template
object, instantiated with your template.$previous_values
is an associative array of the stored data (for editing and detecting changes)$Things
is a Thing factory object, from a class that inheritsPerchAPI_Factory
$Thing
is the object you're editing (or it can be false), from a class that inheritsPerchAPI_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.
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.