Rendering Page Attribute Form Inputs

Permalink
I'm building a real estate website which requires the user to be able to enter listings.

I set up a "property_detail" pagetype and associated a bunch of page attributes like "rent", "contact_info", etc.

Now I am adding a Single Page named "add_property" which will allow the user to enter the values for these attributes, then automatically create a page of that pagetype and assign the appropriate attributes.

I'd like to let C5 render the form elements for me instead of hardcoding them.

I had a look at the form attributes helper, but got no where using it, so then I turned to the c5 core files and found some code that seemed to do what I wanted.

I adapted it to my page like so..

<?php
$form = Loader::helper('form');
Loader::model("collection_types");
Loader::model('attribute/categories/collection');
   $cto = CollectionType::getByHandle('property_detail');
   $aks = $cto->getAvailableAttributeKeys();
   foreach($aks as $ak) { ?>
      <label><?php echo $ak->getAttributeKeyName()?></label><?php
      echo $ak->render('form');
   }?>


This renders the elements as required but the html seems incomplete. Here is an example of the output of the code above.

<label>rent</label><input id="akID[31][value]" type="text" name="akID[31][value]" value="" style="width:80px" style="width:80px" class="ccm-input-text" />


I would expect the attribute handle to be the name and id, instead I am getting what looks like the name of the variable that would hold that name..

Can someone either point out where this "render" function lives so I can examine the code, or lend a helping hand on the process of calling out attributes to be rendered in a form?

guythomas
 
andrew replied on at Permalink Reply
andrew
Could you post how you'd like it to display ideally?
guythomas replied on at Permalink Reply
guythomas
I would personally be happy if it simply used the attribute handle as the "name" and "id".

<label>rent</label><input id="rent" type="text" name="rent" value="" style="width:80px" style="width:80px" class="ccm-input-text" />


This is obviously only for a simple text input. For a select box, or checkbox, I would like the same as above and then have the options name and value as they are within the attribute.

But really, I would probably be happiest, if there were some working examples of using the "Form Attribute Helper" to perform this task.
jordanlev replied on at Permalink Reply
jordanlev
What I'd be interested to know isn't so much how to change the form on the front-end, but what code in the form processing can utilize the "ak[31][value]" -- is there some built-in library that automatically maps those to the proper place in the attribute model / database?
guythomas replied on at Permalink Reply
guythomas
That is a very good point. I suppose it wouldn't matter what the inputs were named, as long as there was a way within the controller that is processing the form input to place the submitted values into their proper places on the page I am creating with the data submitted.
melat0nin replied on at Permalink Reply
melat0nin
Did you ever find a solution to this (pretty big) problem? I've come across it too.

EDIT: the problem with hard-coding forms is that if there's an error, the entered values are lost when the form is submitted and the error messages are shown. Using the c5 api methods, the values are retained so the user can edit them and resubmit.