You are here

public function Braintree_Error_ErrorCollection::onHtmlField in Commerce Braintree 7

return errors for the passed html field. For example, $result->errors->onHtmlField("transaction[customer][last_name]")

Parameters

string $field:

Return value

array

File

braintree_php/lib/Braintree/Error/ErrorCollection.php, line 75

Class

Braintree_Error_ErrorCollection
Handles validation errors

Code

public function onHtmlField($field) {
  $pieces = preg_split("/[\\[\\]]+/", $field, 0, PREG_SPLIT_NO_EMPTY);
  $errors = $this;
  foreach (array_slice($pieces, 0, -1) as $key) {
    $errors = $errors
      ->forKey(Braintree_Util::delimiterToCamelCase($key));
    if (!isset($errors)) {
      return array();
    }
  }
  $finalKey = Braintree_Util::delimiterToCamelCase(end($pieces));
  return $errors
    ->onAttribute($finalKey);
}