in this function

function form_set_error(){

}

There is a condition:

if (isset($name) && !isset($form[$name])) {

}
return $form;

But normally the condition seems hard to understand

!isset($form[$name])

Because we normally use the element name in the form, and it seems working well.

for example,

Comments

Jaypan’s picture

The variable name $form is misleading here, as it is not referring to a form element. Look at this bit of code further down the function:

if ($record) {
  $form [$name] = $message;
  if ($message) {
    drupal_set_message($message, 'error');
  }
}

$message is the error message. $name is the key of the form element to which the error should be applied. So they are using $form[$name] to store error messages.

So back to your original question:

if (isset($name) && !isset($form[$name])) {

This is saying 'if $name is set, and a message hasn't been saved to $form[$name]'.


Checkout my Japan podcasts.
qqboy’s picture

you are exactly totally right. thanks.