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
}
}
大家好,以上是给我一个“Undefined offset:4”错误的代码。我已经尝试使用isset()和其他一些东西,我继续得到错误。你能救我吗?我还很新,还在学习。
感谢。
答案 0 :(得分: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
}
Viola,效果很好!