Thread tagged as: Problem, Api, Runway

'perch_' Added to Input Name When Using $Form->receive_from_template_fields()


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

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?


Jack Barber

Jack Barber 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

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 which would cause this...


$Things = new BusinessListings_Businesses($API);

$HTML     = $API->get('HTML');
$Form     = $API->get('Form');
$Text     = $API->get('Text');
$Template = $API->get('Template');

// Load master template
$Template->set('businesslistings/my_listing.html', 'input');


$result = false;
$message = false;

//check to see if we have an ID on the QueryString
//If yes, this is an edit. Get the object and turn it into an array
$thingID = (int) $_GET['id'];    
$Thing = $Things->find($thingID, true);
$details = $Thing->to_array();
$heading1 = 'Edit Listing';

if ($Form->submitted()) {

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

    //if we have a Thing update it
    if (is_object($Thing)) {
        $result = $Thing->update($data);

    if ($result) {
        $message = $HTML->success_message('Your thing has been successfully updated. Return to %sthing listing%s', '<a href="'.$API->app_path() .'">', '</a>');  
        $message = $HTML->failure_message('Sorry, that thing could not be updated.');

    if (is_object($Thing)) {
        $details = $Thing->to_array();
        $details = array();


# Side panel
echo $HTML->side_panel_start();

echo $HTML->side_panel_end();

# Main panel
echo $HTML->main_panel_start();

echo $HTML->heading1($heading1);

if ($message) echo $message; 
echo $HTML->heading2('Edit Listing Below');

echo $Form->form_start();

echo $Form->fields_from_template($Template, $details);

echo $Form->submit_field('btnSubmit', 'Update', $API->app_path());

echo $Form->form_end();

echo $HTML->main_panel_end();


Drew McLellan

Drew McLellan 2638 points
Perch Support

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:

  • The site will contain a lot of user generated content, this part is a directory of businesses
  • Members register (standard Members Add-on) and then within their account there is a page which contains the form to accept the data from the member (business name, description and so on) - this is part of the add-on so it is called like this:
  • Once a member has submitted their data it becomes available to view within Apps -> Business Listings within Perch
  • Administrators can then view/edit the data as required

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.

Drew McLellan

Drew McLellan 2638 points
Perch Support

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:

<perch:form id="updateListing" method="post" app="businesslistings" type="default">

<h2>About Your Business</h2>

    <perch:label for="listingTitle">Listing Title</perch:label>
    <perch:input type="text" id="listingTitle" required="true" label="Listing Title" />
    <perch:error for="listingTitle" type="required">Please add your listing title</perch:error>

    <perch:label for="listingIntro">Listing Introduction - Briefly Describe Your Business</perch:label>
    <perch:input type="text" id="listingIntro" required="true" label="Listing Intro" maxlength="140" />
    <perch:error for="listingIntro" type="required">Please add your listing introduction</perch:error>

    // etc...
Drew McLellan

Drew McLellan 2638 points
Perch Support

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.