mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-19 14:43:49 +09:00
Fixed conditional form fields
This commit is contained in:
@@ -155,6 +155,8 @@
|
||||
|
||||
foreach( $fields as $key => $array ) {
|
||||
|
||||
$array = apply_filters('um_get_custom_field_array', $array, $fields );
|
||||
|
||||
if ( isset( $array['type'] ) && $array['type'] == 'checkbox' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) ) {
|
||||
$ultimatemember->form->add_error($key, sprintf(__('%s is required.','ultimatemember'), $array['title'] ) );
|
||||
}
|
||||
|
||||
@@ -581,6 +581,7 @@ class UM_Fields {
|
||||
|
||||
if ( isset( $array['conditions'] ) && is_array( $array['conditions'] ) && !$this->viewing ) {
|
||||
$array['conditional'] = '';
|
||||
|
||||
foreach( $array['conditions'] as $cond_id => $cond ) {
|
||||
$array['conditional'] .= ' data-cond-'.$cond_id.'-action="'. $cond[0] . '" data-cond-'.$cond_id.'-field="'. $cond[1] . '" data-cond-'.$cond_id.'-operator="'. $cond[2] . '" data-cond-'.$cond_id.'-value="'. $cond[3] . '"';
|
||||
}
|
||||
|
||||
@@ -261,4 +261,44 @@
|
||||
|
||||
return $array;
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
*** @validate conditional logic
|
||||
***/
|
||||
add_filter('um_get_custom_field_array', 'um_get_custom_field_array',99,2);
|
||||
|
||||
function um_get_custom_field_array( $array, $fields ){
|
||||
|
||||
if( isset( $array['conditions'] ) ){
|
||||
$found = 0;
|
||||
for( $a = 0; $a < count( $array['conditions'] ); $a++ ){
|
||||
if( isset( $array['conditional_value'] ) || isset( $array['conditional_value'.$a] ) ){
|
||||
|
||||
if( isset( $array['conditions'] ) && ! empty( $array['conditions'] ) ){
|
||||
|
||||
$arr_conditions = array();
|
||||
|
||||
foreach ($array['conditions'] as $key => $value) {
|
||||
$metakey = $fields[ $value[1] ]['metakey'] ;
|
||||
$arr_conditions[ $metakey ] = $_POST[ $metakey ];
|
||||
}
|
||||
|
||||
foreach ($array['conditions'] as $key => $value) {
|
||||
$metakey = $fields[ $value[1] ]['metakey'] ;
|
||||
$arr_conditions[ $metakey ] = $_POST[ $metakey ];
|
||||
if( isset( $_POST[ $metakey ] ) && isset( $array['conditional_value'] ) && $_POST[ $metakey ] !== $array['conditional_value'] ){
|
||||
$array['required'] = 0;
|
||||
}
|
||||
if( isset( $_POST[ $metakey ] ) && isset( $array['conditional_value'.$a] ) && $_POST[ $metakey ] !== $array['conditional_value'.$a] ){
|
||||
$array['required'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
Reference in New Issue
Block a user