Forum
'perch_' Added to Input Name When Using $Form->receive_from_template_fields()
Hi
I've got 90% of the way through builing my first Add-on for a site I'm working on. I've used the Sample App as a framework and have just about go my head around it, but I've got stuck processing the form within Perch (Runway 2.8.29) - as follows:
I'm setting my form template like this (in edit.pre.php):
$Template->set('businesslistings/my_listing_admin.html', 'businesslistings');
I'm setting my fields like this (in edit.post.php):
echo $Form->fields_from_template($Template, $details);
And then attempting to get the fields and process the data using this:
$data = $Form->receive_from_template_fields($Template, $details, $Things, $Thing);
But whatever I do I always see this in view source, with 'perch_' appended to my field name/id which then causes a mismatch with my database structure:
<input type="text" id="perch_listingTitle" name="perch_listingTitle" value="Jack Barber Ltd #5" class="text " />
Any ideas?
Thanks!
We modify the ID in the source because it's managed by Perch to make sure there aren't conflicting IDs. The API should abstract that away though - you shouldn't get prefixed values back from the API.
Thanks - that's what I thought. I'm using the same template for the front end (via the customer-facing website) and the backend within Perch. The frontend works fine (stripping perch_ from the input name and saving the data correctly) but the inputs for Administrators retain perch_.
Can you spot anything in my edit.pre.php or edit.post.php which would cause this...
edit.pre.php:
edit.post.php
Thanks.
You mention frontend and backend, but you've not explained what you're trying to do, so I'm not sure how to help.
Sorry Drew - here's some more info:
So far a member can register and submit their data and I can view it within Perch, but get errors when trying to update the listing via the add-on in Perch due to the mistmatched form fields.
If perch_ wasn't appended to the each input their would be no problem - but I can't see how to get around this problem.
Does that make sense?
Thanks for looking.
What steps are you taking to translate the more complex data formats output but the backend field types into the simplistic ones used by front-end forms?
Perhaps this is where I'm coming unstuck... I'm just using perch:input in my template (my_listing.html) to create the input elements:
The data structures returned by
perch:input
tags and those returned by the content field types are different. You can't take one set of data and edit it directly through both mechanisms - you'll need to do some translation back and forth between the two.