我试图将数据发布到第三方API,并且取决于我需要取消表单提交的响应。但我仍然在重力形式的后端获得表单条目。
这是我的代码:
add_filter('gform_validation_10', 'stop_form_submission_validation');
function stop_form_submission_validation($validation_result){
$form = $validation_result['form'];
foreach ( $form['fields'] as $field ) {
//NOTE: replace 1 with the field you would like to validate
if ( $field->id == 1 ) {
// set the form validation to false
$validation_result["is_valid"] = false;
$field->failed_validation = true;
$field->validation_message = 'This field is invalid!';
break;
}
}
$validation_result['form'] = $form;
return $validation_result;
}
答案 0 :(得分:0)
您需要通过引用分配数组值。否则,您正在修改数组项的副本,而不是项目本身。
改变这个:
foreach ( $form['fields'] as $field ) {
对此:
foreach ( $form['fields'] as &$field ) {