switching part of a button option to be a radio - php

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.

Related

How can i get the name by ID in input type text?

i can call my input value using the foreach ($sub_category as $k => $v) and with the value="<?php echo $v['id'] ?>" <?php if(in_array($v['id'], $sub_category_data)) { echo 'selected="selected"'; } ?>><?php echo $v['name'] ?> but that was in select box my question here is that if i want to convert it into an input type textview how can i get the value?
<div class="form-group">
<label for="sub_category">Category:</label>
<?php $sub_category_data = json_decode($product_data['sub_category_id']); ?>
<select class="form-control select_group" id="sub_category_1" name="sub_category[]" onchange="getSubCategoryData(1)">
<?php foreach ($sub_category as $k => $v): ?>
<option value="<?php echo $v['id'] ?>" <?php if(in_array($v['id'], $sub_category_data)) { echo 'selected="selected"'; } ?>><?php echo $v['name'] ?></option>
<?php endforeach ?>
</select>
</div>
what should i add to call the markup using the sub category id just like in the select box without using the foreach?
<div class="form-group">
<label for="markup">Markup:</label>
<input type="text" class="form-control" id="markup" name="markup" disabled value="" autocomplete="off" placeholder="Markup">
<input type="hidden" class="form-control" id="markup_value" name="markup_value" value="" autocomplete="off">
</div>

Remove last empty line from select field with "for" loop wordpress

I am create a custom widget in WordPress and in the widget I try to create a select field with for loop and shows in it 10 numbers from 1 to 10.
I created BUT underneath number 10 it have an empty line.
Can you help me to remove that empty line?
<label for="<?php echo $this->get_field_id('text'); ?>">
<select width="50" style="width: 50px" class='widefat' id=" <?php $this->get_field_id('timet8t2'); ?>" name="<?php $this->get_field_name('timet8t2'); ?>" type="text">
<?php
for($i=1; $i<11; $i++)
{
echo "<option value=".$i.">"."$i<br>"."</option>";
}
?>
<option name="<?php $this->get_field_name('timet8t2'); ?>"> </option>
</select>
</label>
Part 1
You need to remove the last option:
<option name="<?php $this->get_field_name('timet8t2'); ?>"><?= $this->get_field_name('timet8t2'); ?></option>
Part 2
To display the option label with a leading 0, you can use sprintf().
See Below:
<label for="<?php echo $this->get_field_id('timet8t2'); ?>">
<select width="50" style="width: 50px" class='widefat' id=" <?php $this->get_field_id('timet8t2'); ?>" name="<?php $this->get_field_name('timet8t2'); ?>" type="text">
<?php
for($i=1; $i<11; $i++)
{
echo "<option value=".$i.">". sprintf("%'.02d", $i) . "</option>";
}
?>
</select>
</label>
Simplified PHPSandbox

Refinement bar with multiple options submitted

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>

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...

How to change position of product options?

Is there a way to change position of product options? I want to show options below product quantity.
I tried to call wrapper.phtml in app/design/frontend/gallins/default/template/catalog/product/view/addtocart.phtml but couldn't get it to work.
What I have right now is:
- option
- qty
- add to cart button
But I wan't options to be shown below qty.
addtocart.phtml ->
<?php $_product = $this->getProduct(); ?>
<?php $buttonTitle = $this->__('Add to Cart'); ?>
<?php if ($_product->isSaleable()): ?>
<div class="add-to-cart">
<?php if (!$_product->isGrouped()): ?>
<div class="quantity">
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<div class="clear"></div>
</div>
<?php endif; ?>
<!-- This is where I want to show options -->
<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
<?php echo $this->getChildHtml('', true, true) ?>
</div>
I tried <?php echo $this->getChildHtml('wrapper'), but that didn't work.
you have to make 2 changes in 2 files as if you have product options then
in addtocart.phtml
<?php $_product = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>
<?php $buttonTitle = $this->__('Add to Cart'); ?>
<?php if($_product->isSaleable()): ?>
<div class="add-to-cart">
<?php if(!$_product->isGrouped()): ?>
<?php if (count($_attributes) == 0):?>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<?php endif; ?>
<?php endif; ?>
<button type="button" title="<?php echo $buttonTitle ?>" class="button btn-cart" onclick="productAddToCartForm.submit(this)"><span><span><?php echo $buttonTitle ?></span></span></button>
<?php echo $this->getChildHtml('', true, true) ?>
</div>
<?php endif; ?>
and Please also change in options\configurable.phtml file change like below
<?php
$_product = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<dl>
<?php foreach($_attributes as $_attribute): ?>
<dt><label class="required"><em>*</em><?php echo $_attribute->getLabel() ?></label></dt>
<dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
</div>
</dd>
<?php endforeach; ?>
</dl>
<script type="text/javascript">
var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
</script>
<?php endif;?>
let me know if i can help you more.

Categories