Refinement bar with multiple options submitted - php

I am trying to create a refinement bar with multiple filter options submitted in the form. Currently I have the form just submitting one option, can someone please tell me what I am missing in my code?
<form action="" method="post">
<div id="box">
<p>Occasion:</p>
<?php
$rs=mysql_query('select DISTINCT occasion from cakes');
?>
<select name="occasion"onchange='location=this.options[this.selectedIndex].value;'>
<?php
$path="filter1.php?search=";
while($record=mysql_fetch_assoc($rs)){
?>
<option value="<?php echo $path.$record['occasion']; ?>"><?php echo $record['occasion']; ?></option>
<?php
}
?>
</select>
</div>
<div id="box">
<p>Styles:</p>
<?php
$rs=mysql_query('select DISTINCT style from cakes');
?>
<select name="style" onchange='location=this.options[this.selectedIndex].value;'>
<?php
$path="filter1.php?choice=";
while($record=mysql_fetch_assoc($rs)){
?>
<p><option value="<?php echo $path.$record['style']; ?>"><?php echo $record['style']; ?></option></p>
<?php
}
?>
</select>
</div>
<div id="box">
<p>Colours:</p>
<?php
$rs=mysql_query('select DISTINCT colour from cakes');
?>
<select name="colour" onchange='location=this.options[this.selectedIndex].value;'>
<?php
$path="filter1.php?choice=";
while($record=mysql_fetch_assoc($rs)){
?>
<p><option value="<?php echo $path.$record['colour']; ?>"><?php echo $record['colour']; ?></option></p>
<?php
}
?>
</select>
</div>
<div id="box">
<p>Filling:</p>
<?php
$rs=mysql_query('select DISTINCT filling from cakes');
?>
<select name="filling"
onchange='location=this.options[this.selectedIndex].value;' >
<?php
$path="filter1.php?choice=";
while($record=mysql_fetch_assoc($rs)){
?>
<p><option value="<?php echo $path.$record['filling']; ?>"><?php echo $record['filling']; ?></option></p>
<?php
}
?>
</select>
<p>
</div>
<div id="box">
<p>Topping:</p>
<?php
$rs=mysql_query('select DISTINCT topping from cakes');
?>
<select name="topping"
onchange='location=this.options[this.selectedIndex].value;' >
<?php
$path="filter1.php?choice=";
while($record=mysql_fetch_assoc($rs)){
?>
<p><option value="<?php echo $path.$record['topping']; ?>"><?php echo $record['topping']; ?></option></p>
<?php
}
?>
</select>
<p>
</div>
</form>

Related

Select Picker Is Not Showing When i call Using Ajax

I am Calling this File using Ajax But this file is displaying but without selectpicker, I don't see any error if anyone can help me?
Bootstrap Selectpicker Will Show Timing From Monday to Sunday
IF condition is used to check whether this time is present in the database or not if present check the checkbox and show the time in bootstrap Selectpciker
All the condition displaying in this file is important I cant remove them
<?php
error_reporting(E_ALL);
ini_set("display_errors",1);
require_once'configuration/config.php';
date_default_timezone_set("Asia/Kolkata");
$startTime = strtotime(date("H:i:s",strtotime('00:00:00')));
$endTime = strtotime(date('H:i:s',strtotime('23:59:00')));
if(isset($_POST['doc_id'])){
$days = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'];
$doc_id ='921007GAURAV984934';
$hp_id = 'INRJAPPO2E381F220220';
$stmt = $con->prepare('SELECT * FROM tb_doc_loc WHERE doc_id=? AND hp_id= ?');
$stmt->bind_param('ss',$doc_id,$hp_id);
$stmt->execute();
$res = $stmt->get_result();
while($row = $res->fetch_array()){
$data = $row['datas'];
}
$datas = explode(',',$data);
$chunk = array_chunk($datas,5);
for($i=0;$i<count($chunk);$i++): ?>
<?php if($chunk[$i][0] == $days[$i]): ?>
<tr>
<td>
<div class=" form-check" style="margin-top: 7px;">
<input class="form-check-input" type="checkbox" name="edit_days" value="<?php echo $chunk[$i][0]?>" checked="checked">
<?php echo $chunk[$i][0]?>
</div>
</td>
<td>
<div class="form-group">
<div class="row">
<div class="col-sm-6">
<label>Morning Timings</label><br>
<select class="selectpicker " id="<?php echo $chunk[$i][0]?>_Morning_time" title="Select Timings" multiple data-max-options="2" data-size="5">
<?php for($k=$startTime;$k<=$endTime;$k = $k + 30*60): ?>
<option value="<?php echo date('H:i',$k);?>"<?php if($chunk[$i][1] == date('H:i',$k) ||$chunk[$i][2] == date('H:i',$k)){echo"Selected";}?> ><?php echo date('H:i',$k)?></option>
<?php endfor; ?>
</select>
</div>
<div class="col-sm-6">
<label>Evening Timings</label><br><!-- line 73 -->
<select class="selectpicker" id="<?php echo $chunk[$i][0]?>_Evening_time" title="Select Timings" multiple data-max-options="2" data-size="5">
<?php for($k=$startTime;$k<=$endTime;$k = $k + 30*60): ?>
<option value="<?php echo date('H:i',$k);?>"<?php if($chunk[$i][3] == date('H:i',$k) ||$chunk[$i][4] == date('H:i',$k)){echo"Selected";}?> ><?php echo date('H:i',$k)?></option>
<?php endfor; ?>
</select>
</div>
</div>
</div>
</td>
</tr>
<?php endif;?>
<?php endfor;?>
<?php for($j=$i;$j<count($days);$j++): ?>
<tr>
<td>
<div class=" form-check" style="margin-top: 7px;">
<input class="form-check-input" type="checkbox" name="edit_days" value="<?php echo $days[$j]?>"><?php echo $days[$j]?>
</div>
</td>
<td>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label >Morning Start</label><br>
<select class="selectpicker " id="<?php echo $days[$j]?>_Morning_time" title="Select Timings" multiple data-max-options="2" data-size="5">
<?php for($k=$startTime;$k<=$endTime;$k = $k + 30*60): ?>
<option value="<?php echo date('H:i',$k)?>"><?php echo date('H:i',$k)?></option>
<?php endfor; ?>
</select>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label >Morning End</label><br>
<select class="selectpicker " id="<?php echo $days[$j]?>_Evening_time" title="Select Timings" multiple data-max-options="2" data-size="5" >
<?php for($k=$startTime;$k<=$endTime;$k = $k + 30*60): ?>
<option value="<?php echo date('H:i',$k)?>"><?php echo date('H:i',$k)?></option>
<?php endfor; ?>
</select>
</div>
</div>
</div>
</td>
</tr>
<?php endfor;
}
?>
output of this model:
SelectPicker is displaying when I use inspect element on the main page but problem what I find it having CSS property
.bootstrap-select > select.bs-select-hidden, select.bs-select-hidden, select.selectpicker {
display: none !important;
}
[2
why I don't know
Finally, I got the answer after reading documentation again and again that I have to call selectpicker function after displaying the Ajax output.
Ajax Call:-
$('.editModals').on('click',function(){
docId = $(this).attr('id');
$.ajax({
url:'doc_timings2.php',
data:{doc_id:docId},
type:'POST',
success:function(data){
$('#display').html(data);
$('select').selectpicker();// That's the function
}
});

Why I can't use chained jquery in loop condition?

<?php
foreach ($employee as $data) {
?>
<tr>
<td>
<form action="<?php echo base_url();?>controller_admin/updateEmployee/<?php echo $data->id_employee;?>" method="post">
<select style="width: 100px; height: 33px;" name="directorate" id="directorate">
<option selected value="<?php echo $data->id_directorate ?>"><?php echo $data->directorate ?></option>
<?php
foreach ($directorate as $key) {
if ($data->directorate != $key->directorate) {?>
<option value="<?php echo $key->id_directorate ?>">
<?php echo $key->directorate; ?>
</option>
<?php
}
}
?>
</select>
</td>
<td>
<select style="width: 100px; height: 33px;" name="department" id="department">
<?php if ($data->id_department!=null) {?>
<option value="0"></option>
<?php
} ?>
<option selected value="<?php echo $data->id_department ?>"><?php echo $data->department; ?></option>
<?php
$value = 1;
foreach ($department as $key) {
if ($data->department != $key->department) {?>
<option
class="<?php echo $key->id_directorate ?>"
value="<?php echo $value ?>">
<?php echo $key->department; ?>
</option>
<?php
$value++;
}
}
?>
</select>
</td>
<td>
<select style="width: 100px; height: 33px;" name="section" id="section">
<?php if ($data->id_section!=null): ?>
<option value="0"></option>
<?php endif ?>
<option selected value="<?php echo $data->id_section ?>"><?php echo $data->section; ?></option>
<?php
$value = 1;
foreach ($section as $key) {
if ($data->section != $key->section) {?>
<option
class="<?php echo $key->id_department ?>"
value="<?php echo $value ?>">
<?php echo $key->section; ?>
</option>
<?php
$value++;
}
}
?>
</select>
</td>
<td>
<button type="submit" class="btn btn-warning"><i class="fa fa-edit"></i></button>
<button type="button" class="btn btn-danger"><i class="fa fa-trash-o"></i></button>
</form>
</td>
<?php
}
?>
<script src="<?php echo base_url();?>assets/js/jquery.chained.min.js"></script>
<script>
$("#department").chained("#directorate");
$("#section").chained("#department");
</script>
I want to make a list of table to display chained dropdown to display like this:
and chained dropdown work like this:
but, it will display in first row only, at another row, it does not work.
You can look like this:
I hope I can chained dropdown for all rows. Anyone find the solution?
you could try to put your js code inside the ready function - its possible that the elements are not even rendered when you try to select them.
<script>
$( document ).ready(function() {
$("#department").chained("#directorate");
$("#section").chained("#department");
});
</script>
reference: http://learn.jquery.com/using-jquery-core/document-ready/

switching part of a button option to be a radio

Okay guys so my problem here is I need to show some pictures of colors that people can use to pick the color of a cover. Right now its set up to be a drop down and just select the color but we want to switch it over to be the colors.
Here is the code we have set up right now.
<select name="option[<?php echo $option['product_option_id']; ?>]" id="input-option<?php echo $option['product_option_id']; ?>" class="form-control">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($option['product_option_value'] as $option_value) { ?>
<option value="<?php echo $option_value['product_option_value_id']; ?>"
<?php if(array_key_exists('poid', $_REQUEST)) { ?>
<?php if($option_value['product_option_value_id']==$_REQUEST['poid']){ echo "selected"; }}?>>
<?php echo $option_value['name']; ?>
<?php if ($option_value['price']) { ?>
(<?php echo $option_value['price_prefix']; ?>
<?php echo $option_value['price']; ?>)
<?php } ?>
</option>
<?php } ?>
</select>
And this is what I've come up with so far.
<?php if ($options) { ?>
<?php foreach ($options as $option) { ?>
<?php foreach ($option['product_option_value'] as $option_value) {
//echo $option_value['image'];
if($option_value['image']){ ?>
<div class="button">
<input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" id="input-option<?php echo $option['product_option_id']; ?>" />
<img src="<?php echo $option_value['image']?>" />
<label "<?php echo $option_value['name'];?>" </label>
</div>
<?php }}} }?>
Another concern is we have other button options that need to keep working for other selections.
Your <label> syntax is wrong. It should produce:
<label for="button ID">Name</label>
but you're printing:
<label "Name" </label>
Or you can simply wrap a <label> tag around both the button and the name, as I've done below.
<div class="button">
<label>
<input type="radio" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option_value['product_option_value_id']; ?>" />
<img src="<?php echo $option_value['image']?>" />
<?php echo $option_value['name'];?>
</label>
</div>
I got rid of the id on the button because it was creating duplicate IDs on all the buttons in the same radio group, and is probably not needed.
Other than that problem, I think it should work.

How customize values on products filter bar wordpress

I need to modify the value and name of the products filter in a Wordpress template that I've purchased.
The template is Automotive - Templatic. I need to change values and name of filter products filter. I'm trying to change this PHP code:
<form id="search_car" name="search_car" action="<?php echo home_url(); ?>" method="get">
<input type="hidden" name="search" id="search" value="vehicle" />
<div class="selectbox select1">
<input type="text" value="<?php the_search_query(); ?>" name="s" id="s" placeholder="<?php _e('Model , Name etc...',T_DOMAIN); ?>">
</div>
<span class="shape2"><?php _e('OR',T_DOMAIN); ?></span>
<?php if($post_category): ?>
<div class="selectbox select2">
<select class="select" title="<?php _e("All Makes",T_DOMAIN); ?>" name="makes" id="makes">
<option value=""><?php _e("All Makes",T_DOMAIN); ?></option>
<?php
$args = array( 'taxonomy' => 'vcategory' );
$terms = get_terms( 'vcategory',$args);
foreach ( $terms as $term ):
?>
<option value="<?php echo $term->term_id; ?>" <?php if($_REQUEST['makes'] == $term->term_id){ ?> selected="selected" <?php } ?>><?php echo esc_attr( $term->name ); ?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
<?php if($model_status): ?>
<div class="selectbox select2">
<select class="select" title="<?php _e('All Models',T_DOMAIN); ?>" name="status" id="model_status">
<option value=""><?php _e('All Models',T_DOMAIN); ?></option>
<?php
$explode = explode(",",$option);
foreach($explode as $_explode):
?>
<option value="<?php echo $_explode; ?>" <?php if($_REQUEST['status'] == $_explode){ ?> selected="selected" <?php } ?>><?php echo sprintf(__('%s',T_DOMAIN),$_explode); ?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
<?php if($fuel): ?>
<div class="selectbox select2">
<select class="select" title="<?php _e('All Type',T_DOMAIN); ?>" name="fuel" id="fuel">
<option value=""><?php _e('All Type',T_DOMAIN); ?></option>
<?php
$fuel_exp = explode(",",$fuel_option);
foreach($fuel_exp as $_fuel_option):
?>
<option value="<?php echo $_fuel_option; ?>" <?php if($_REQUEST['fuel'] == $_fuel_option){ ?> selected="selected" <?php } ?>><?php echo sprintf(__('%s',T_DOMAIN),$_fuel_option); ?></option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
I have to create 3 dropdown fields and 1 text area field. Can you help me?
Thanks in advance...

Magento: Get country that user has chosen

I have a piece of code which creates dropdown list of the countries
<div class="input-box">
<?php $_countries = Mage::getResourceModel('directory/country_collection')->loadData()->toOptionArray(false) ?>
<?php if (count($_countries) > 0): ?>
<select name="country" id="country" onchange="print()">
<option value=""> </option>
<?php foreach($_countries as $_country): ?>
<option value="<?php echo $_country['value'] ?>">
<?php echo $_country['label'] ?>
</option>
<?php endforeach; ?>
</select>
<?php endif; ?>
</div>
I can't figure out how to get the country which user has chosen. Can you please help me?
<div class="input-box">
<?php $_countries = Mage::getResourceModel('directory/country_collection')->loadData()->toOptionArray(false) ?>
<?php if (count($_countries) > 0): ?>
<select name="country" id="country" onchange="showCountry(this)">
<option value=""> </option>
<option value="<?php echo $_country['value'] ?>" <?php echo $select; ?> >
<?php echo $_country['label'] ?>
</option>
<?php endforeach; ?> </select>
<?php endif; ?>
</div>
function showCountry​(ele){
alert(ele.value);
} ​

Categories