validate() function within block controllers

Permalink
Hi

I'm looking to run validation within my block controller but I'm struggling to access variables.

In my code I have a field called "start_stack". This is just one example of many, that I'm wanting to access in my validate() function.

I've used the following code to attempt to debug:
public function validate() {
      $error = Loader::helper('validation/error');
      $error->add('stack_start contents: ' . $stack_start);
      $error->add('stack_start obj contents: ' . $this->stack_start);
      if($error->has()) {
         return $error;
      }
   }


Both the variables $stack_start and $this->stack_start return nothing.

Why are the variables accessible at this start of the execution?

Thanks.

Job
 
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
At this point the variables are still request parameters. Try:
$_POST['start_stack']
mkly replied on at Permalink Reply
mkly
If anyone comes across this, the validate method is passed in the arguments of the fields. So you can get them via
/**
 * $args is an array of form fields
 * $error is a ValidationHelperObject
 * if $error contains no errors the field
 * with submit successfully but if there are
 * errors the user will get a dialog with
 * them listed.
 */
public function validate($args) {
  $error = Loader::helper('validation/error');
  if(ctype_digit($args['something']) === false) {
    $error->add(t('Something must me a number'));
  }
  return $error;
}
Job replied on at Permalink Reply
Job
God it's strange you bump this now. Literally 10 minutes ago I asked aghouseh about this again (silly me forgetting stuff).

Cheers mkly.