functionto $_POST url constructed with js method 03
This commit is contained in:
parent
99b0a39d3f
commit
6959347849
|
@ -60,15 +60,10 @@ if( ! function_exists( 'ofisuport_ajuts_filters_form' ) ):
|
||||||
<h5><?php echo $fields['label'];?></h5>
|
<h5><?php echo $fields['label'];?></h5>
|
||||||
<?php foreach( $fields['choices'] as $choicevalue => $choicelabel ) { ?>
|
<?php foreach( $fields['choices'] as $choicevalue => $choicelabel ) { ?>
|
||||||
|
|
||||||
<div class="filter" data-filter="<?php echo $fields['name'];?>">
|
<div class="filter" data-filter="<?php echo $fields['name'];?>">
|
||||||
<input
|
<input class="ofisuport-filter" type="checkbox" name="<?php echo $fields['name'];?>" <?php if( in_array($choicevalue,$filteredvalues['value']) ) { echo 'checked';}; ?> value="<?php echo $choicevalue ?>" />
|
||||||
class="ofisuport-filter"
|
<label for="<?php echo $choicevalue; ?>"><?php echo $choicelabel;?></label>
|
||||||
type="checkbox"
|
</div>
|
||||||
<?php if( in_array($choicevalue,$filteredvalues['value']) ) { echo 'checked';}; ?>
|
|
||||||
value="<?php echo $choicevalue ?>"
|
|
||||||
name="<?php echo $fields['name'];?>" />
|
|
||||||
<label for="<?php echo $choicevalue; ?>"><?php echo $choicelabel;?></label>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php };//end foreach fields['choices'] ?>
|
<?php };//end foreach fields['choices'] ?>
|
||||||
|
|
||||||
|
@ -106,42 +101,56 @@ if( ! function_exists( 'ofisuport_ajuts_filters_form' ) ):
|
||||||
// vars
|
// vars
|
||||||
var url = '<?php echo home_url('ajuts/'); ?>';
|
var url = '<?php echo home_url('ajuts/'); ?>';
|
||||||
args = {};
|
args = {};
|
||||||
|
var appendtoURL = '';
|
||||||
|
var eachfiltered = '';
|
||||||
|
var valueschecked = '';
|
||||||
|
|
||||||
// loop over filters
|
// loop over filters
|
||||||
$('#archive-filters .filter').each(function(){
|
$('#archive-filters .filter').each(function(){
|
||||||
urldos = url;
|
// check if is first appearance of each
|
||||||
// vars
|
if( eachfiltered != $(this).data('filter') ){
|
||||||
var filteredajuts = $(this).data('filter'),
|
|
||||||
vals = [],
|
|
||||||
allvalueschecked = [];
|
|
||||||
// find checked inputs
|
|
||||||
$(this).find('input:checked').each(function(){
|
|
||||||
vals.push( $(this).val() );
|
|
||||||
var thisvaluechecked = $(this).val();
|
|
||||||
urldos += filteredajuts;
|
|
||||||
});
|
|
||||||
|
|
||||||
// append to args
|
// save already calculated field=val01,val02,val03
|
||||||
args[ filteredajuts ] = vals.join(',');
|
appendtoURL += eachfiltered +'=' +valueschecked +'&';
|
||||||
alert( filteredajuts +'=' +args[ filteredajuts ]);
|
// remove last ','
|
||||||
|
appendtoURL = appendtoURL.slice(0, -1);
|
||||||
|
// start new fieldname filtered
|
||||||
|
eachfiltered = $(this).data('filter');
|
||||||
|
// reset values
|
||||||
|
valueschecked = '';
|
||||||
|
// find checked inputs
|
||||||
|
$(this).find('input:checked').each(function(){
|
||||||
|
// if not empty save value and ,
|
||||||
|
if( $(this).val() != '' ){
|
||||||
|
valueschecked = $(this).val() + ',';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// we have previous values checked
|
||||||
|
// find checked inputs
|
||||||
|
if( $(this).val() != '' ){
|
||||||
|
// if not empty append value and ,
|
||||||
|
$(this).find('input:checked').each(function(){
|
||||||
|
valueschecked += $(this).val() + ',';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// save last cycled filtered value already calculated field=val01,val02,val03
|
||||||
|
appendtoURL += eachfiltered +'=' +valueschecked +'&';
|
||||||
|
|
||||||
|
// remove last &
|
||||||
|
appendtoURL = url.slice(0, -1);
|
||||||
|
|
||||||
// update url
|
// update url
|
||||||
url += '?';
|
url += '?';
|
||||||
|
|
||||||
// loop over args
|
|
||||||
$.each(args, function( name, value ){
|
|
||||||
url += name + '=' + value + '&';
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// remove last &
|
|
||||||
url = url.slice(0, -1);
|
|
||||||
|
|
||||||
// reload page
|
// reload page
|
||||||
//$('#archive-filters button').on('click', function () {
|
//$('#archive-filters button').on('click', function () {
|
||||||
alert( "estoy en: " +url );
|
alert( "estoy en: " +url +appendtoURL);
|
||||||
//window.location.replace( url );
|
//window.location.replace( url );
|
||||||
//});
|
//});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue