Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

Disable HTML output and return array of erroneous fields instead in fValidation

posted by audvare 8 years ago

Is there any way? Doesn't seem like it.

I think it would be useful. I'm working on a solution for myself for now by regexing the list and removing the <p> and contents. And I would like the names of the fields so I can give them a class 'form-error' so they can be styled differently to alert the user.

Not the best solution right now but extending or re-using fValidationException seemed a bit too much. There are many dependencies.

This is in my own exception class which I thrown when I catch an fValidationException.

  public function _unformatMessages($msg) {
    if (preg_match('/<p>The following problems were found:<\\/p>/', $msg)) {
      $find = array('/<p>.*<\\/p>/', '/<ul>/', '/<\\/ul>/', '/<li>/');
      $msg = preg_replace($find, '', $msg);
      $msg = explode('</li>', $msg);
    }
    
    // Unset last due to last </li>
    array_pop($msg);
    
    return $msg;
  }
posted by audvare 8 years ago

You probably want to read fValidation: Returning Messages

posted by wbond 8 years ago

Thanks! That got me exactly what I wanted.

posted by audvare 8 years ago