0
function webform_registrationpw_submit($form, &$form_state) {
// first, we need to identify the password field for this registration form
$node = node_load($form_state['values']['details']['nid']);
$nodePassField = "";

  foreach( $node->webform['components'] as $key => $value ) {
    if ( $value['form_key'] =="password"  ) { 
      $nodePassField = $key;
    }
  }

  if ( "" == $form_state['values']['submitted'][$nodePassField] ) { //this is the line giving the error
    $form_state['values']['submitted'][$nodePassField] = newpw(8);  // set new password
  }
}

大家好,上面是给我“未定义偏移量:4”错误的代码。我尝试使用 isset() 和其他一些东西,但我继续收到错误。你能帮帮我吗?我还是很新,还在学习。

谢谢。

4

1 回答 1

0

事实证明,“if”在寻找空字段时存在一些奇怪的错误。所以删除了if并将代码修改为:

function webform_registrationpw_submit($form, &$form_state) {
// first, we need to identify the password field for this registration form
$node = node_load($form_state['values']['details']['nid']);
$nodePassField = "";

  foreach( $node->webform['components'] as $key => $value ) {
    if ( $value['form_key'] =="password"  ) { 
      $nodePassField = $key;
    }
  }
  $form_state['values']['submitted'][$nodePassField] = newpw(8);  // set new password
}

中提琴,很好用!

于 2013-09-17T15:29:09.163 回答