Can't validate attribute inputs using API

Permalink
Hi all

I've uncovered the same problem as guythomas (described here:http://www.concrete5.org/community/forums/customizing_c5/rendering-...

I'm building a dashboard editing interface with fields which set attributes on the pages which are created. I'm trying to validate those fields, but it doesn't work because the variables which are POSTed don't match the attribute names - they look something like 'akID[12][Value]'.

This means that the validation method I've written (well, tweaked from Andrew's howto) doesn't work. Even if I substitute the attribute name with the name generated by c5, it still doesn't work.

Here's my validation code:

protected function validate() {
      $vt = Loader::helper('validation/strings');
      if (!$vt->notempty($this->post($akID[12][value]))) {
         $this->error->add('Contact email');
         $this->error->add($akID[12][value]);
      }
}


and the bit of the form which generates the field:

<?php             
   Loader::model("attribute/categories/collection");
   $c_email = CollectionAttributeKey::getByHandle('contact_email');
?>
         <strong><?=$c_email->render('label');?></strong>
         <?=$c_email->render('form', $tvalue, true);?>


Any thoughts on a way round this? I tried hard-coding the fields into the page's HTML, which works, but the values entered by the user aren't kept when the form is submitted (which is ironic, because you're told that there's an error in what you've entered - but you can't see what you entered in order to fix it :) )

Any help would be much appreciated, this is a bit of a major stumbling block to my project at the moment.

melat0nin
 
Shotster replied on at Permalink Reply
Shotster
> Any thoughts on a way round this?

There are methods called getRequestValue() and processRequestValue() in "helpers/form.php" which look promising.

-Steve
melat0nin replied on at Permalink Reply
melat0nin
Well I'm trying to get around it another way using the jQuery validate plugin, but it doesn't seem to want to select those weird IDs (akID[12][value]).

Durrr....

EDIT: got there with jQuery. But the problem still applies with the API methinks.
ijessup replied on at Permalink Reply
ijessup
I could have sworn there was a way to validate with only the given post. I'll look into this.

EDIT:
Yeah I think its:
public function validateForm($data)
Untested, but basically something like this...
// @return TRUE if valid input
$valid = AddressAttributeTypeController::validateForm($this->post('akID[12]')
You can add more code that will get which controller is right, but that should put you on the right path.