From 2f834083c98b51791a071d3304b8151cd8b1eeb4 Mon Sep 17 00:00:00 2001 From: jorge-vitrubio Date: Thu, 12 Jan 2023 09:03:16 +0100 Subject: [PATCH] functionto $_POST url constructed with php --- ...m-field-ajuts-filter-function-frontend.php | 240 ++++++++---------- 1 file changed, 104 insertions(+), 136 deletions(-) diff --git a/includes/custom-field-ajuts-filter-function-frontend.php b/includes/custom-field-ajuts-filter-function-frontend.php index 97460ee..d6d170d 100644 --- a/includes/custom-field-ajuts-filter-function-frontend.php +++ b/includes/custom-field-ajuts-filter-function-frontend.php @@ -6,9 +6,6 @@ * basic start * https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/ * - * wordpress full form example - * https://wordpress.stackexchange.com/questions/383599/form-checkbox-value-going-to-dynamic-url - * * checkbox adaptation query * https://wordpress.stackexchange.com/a/102915 * @@ -17,169 +14,140 @@ * * @package Oficina_de_Suport_theme */ -?> -$_POST[submit-ajut] set

'; +// if( !empty($_POST[ $fields['name'] ]) ){ +// echo '

$_POST[$fields[name]] not empty

'; +// foreach( $_POST[ $fields['name'] ] as $post_fields_name ) { +// $post_fields_name_value_checked[] = $post_fields_name; +// }; +// $all_post_fields_name_values_selection[] = $fields['name'] . '=' . implode(',',$post_fields_name_value_checked); +// unset($post_fields_name_values_checked); +// } else { +// echo '

$_POST[$fields[name]] empty

'; +// }; +// //end look for checked values to send +// echo '

after $_POST:' . $url . '

'; +// }; +// // end look checked values to send +//} + if( ! function_exists( 'ofisuport_ajuts_filters_form' ) ): function ofisuport_ajuts_filters_form() { -?> -
- '; // output all possible values of a checkbox + + $groupkey = "group_63ab636898703"; // write here the key for the group of fields from acf if( $groupkey ) { - ?> - -
+ + // start the form + echo ''; - ' . ($field_key['key']) . '
' . '' . ($field_key['label']) . '
' . '' . ($field_key['name']) . '
'; + // https://wordpress.stackexchange.com/a/102915 $fields = get_field_object($field_key['key']); if( $fields ) { + // look checked values to send + //POST_look_values_to_submit(); + // look checked values to send + // https://stackoverflow.com/a/10808238 + if( isset($_POST['submit-ajut']) ){ + echo '

$_POST[submit-ajut] set

'; + if( !empty($_POST[ $fields['name'] ]) ){ + echo '

$_POST[$fields[name]] ' . $fields['name'] . ' not empty

'; + foreach( $_POST[ $fields['name'] ] as $post_fields_name ) { + $post_fields_name_value_checked[] = $post_fields_name; + }; + $all_post_fields_name_values_selection[] = $fields['name'] . '=' . implode(',',$post_fields_name_value_checked); + unset($post_fields_name_values_checked); + } else { + echo '

$_POST[$fields[name]] ' . $fields['name'] . ' empty

'; + }; + //end look for checked values to send + echo '

after $_POST:' . implode('?',$all_post_fields_name_values_selection) . '

'; + }; + // end look checked values to send + // check for values from meta fields db in url foreach( $GLOBALS['my_query_filters'] as $key => $fieldname ) { - // check for values in url and get value if available + // check for values in url + // get value if available if( isset($_GET[ $fieldname ]) ) { $filteredvalues['value'] = explode(',', $_GET[ $fieldname ]); - //$filteredvalues['value'] = ($_GET[ $fieldname ]); }; //end check for values in url + - // construct the checkboxes - if( $fieldname == $fields['name']) { -?> - -
-
- $choicelabel ) { ?> - -
- - value="" - name="" /> - -
- - - -
- - - + // construct the checkboxes + if( $fieldname == $fields['name']) { + + echo ''; + }; + // end of construct checkboxes - + }; + // end check for values from meta fields db in url - + + }; + //end if field_key['key'] - + }; + //end if type checkbox - -

Results:

- -
- + }; + //end foreach groupkey field - + $url = home_url('ajuts/?') . implode('&',$all_post_fields_name_values_selection); + echo '

' . $url . '

'; + //header('Location:'. $url); + echo ''; + echo ''; + //close the form and subit + //POST_look_values_to_submit(); -
+ }; + //end if groupkey - - -'; + }; + //end ofisuport_display_filters() +endif; ?>