It always drops the first checkbox, but not the actual part of the record the checkbox represents. If I keep clicking 'save' it drops off the next checkbox, and the first record. For instance, if the record is 'DMG, SCR, KLS, AST' when I click 'save' and the page refreshed, the DMG checkbox is not checked but the record still says 'DMG, SCR, KLS, AST' If I click it again, the record becomes 'SCR, KLS, AST' and the SCR checkbox is unchecked. The checkbox part of the form is near the bottom.
Thanks!
// delete
if(isset($_GET['id']) && $_GET['x'] == "d") {
$eventType = EventType::find_by_id($_GET['id']);
if($eventType && $eventType->delete()) {
$message = "The Event Type '{$eventType->name}' was deleted.";
} else {
$message = "The Event Type could not be deleted.";
}
}
// save
if(isset($_POST['submit'])) {
$eventType = new EventType();
if(isset($_POST['id'])) {
$eventType->id = mysql_prep($_POST['id']);
}
$eventType->name = mysql_prep($_POST['name']);
$scoreTypes = ScoreType::find_all();
$score_set = array();
foreach($scoreTypes as $scoreType) {
if(isset($_POST[$scoreType->name]) && $_POST[$scoreType->name] == $scoreType->name) {
array_push($score_set, mysql_prep($_POST[$scoreType->name]));
}
}
if(!empty($score_set)) {
$scores = implode(", ", $score_set);
} else {
$scores = "empty";
}
if(isset($scores)) { $eventType->score_types = $scores; } else { $eventType->score_types = ""; }
if(isset($_POST['is_disp'])) { $eventType->is_disp = mysql_prep($_POST['is_disp']); }
$eventType->save();
}
// edit
if(isset($_GET['id']) && ($_GET['x'] == "e")) {
$eventType = EventType::find_by_id($_GET['id']);
}
//view
$eventTypes = EventType::find_all($ord="name");
$scoreTypes = ScoreType::find_all();
?>
<div id="admin_table">
<div id="admin_thead">
<table>
<tr>
<td width="35%">Name</td>
<td width="40%">Score Types</td>
<td width="5%">Display</td>
<td width="7%">Actions</td>
<td width="12"></td>
</tr>
</table>
</div>
<div id="admin_tdata">
<table>
<colgroup></colgroup>
<colgroup class="odd"></colgroup>
<colgroup></colgroup>
<colgroup class="actions"></colgroup>
<?php foreach($eventTypes as $eventType_v): ?>
<tr>
<td width="35%"><?php echo $eventType_v->name; ?></td>
<td width="40%" title="<?php echo $eventType_v->score_types; ?>"><?php echo $eventType_v->score_types; ?></td>
<td width="5%" class="bool"><img src="../images/<?php echo ($eventType_v->is_disp == 1) ? "x_yes.png" : "x_no.png"; ?>"></td>
<td width="7%" class="but_admin"><a class="but_admin_edit" title="edit" href="index.php?con=event_types&id=<?php echo $eventType_v->id; ?>&x=e">edit</a><a class="but_admin_delete" title="delete" href="index.php?con=event_types&id=<?php echo $eventType_v->id; ?>&x=d" onclick="return confirm('Are you sure you want to delete the Event Type <?php echo "\'{$eventType_v->name}\'"; ?>?')">delete</a></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
<div id="admin_ops_cont">
<div id="admin_lt_panel">
<div id="admin_msg">
<h2>Messages</h2>
<p><?php if(!$message) { echo "no message"; } else { echo $message; } ?></p>
</div>
</div>
<div id="admin_form">
<?php if(isset($_GET['id'])) { if(isset($_GET['x'])) { if($_GET['x'] == "e") { $edit = 1; } else { $edit = 0; }}} else { $edit = 0; } ?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>?con=event_types<?php if(isset($_GET['id'])) { echo "&x=e&id={$eventType->id}"; } ?>" method="post">
<fieldset>
<legend><?php if($edit == 1) { echo "Edit: <span>{$eventType->name}</span>"; } else { echo "New EventType"; } ?></legend>
<?php if($edit == 1): ?>
<input type="hidden" name="id" id="id" value="<?php echo $eventType->id; ?>">
<?php endif; ?>
<p>
<label for="name">Name</label>
<input name="name" id="name" type="text"<?php if($edit == 1): ?> value="<?php echo $eventType->name; ?>"<?php endif; ?>>
</p>
<p>
<?php foreach($scoreTypes as $scoreType): ?>
<label for="<?php echo $scoreType->name; ?>"><?php echo $scoreType->description; ?></label>
<input type="checkbox" id="<?php echo $scoreType->name; ?>" name="<?php echo $scoreType->name; ?>" value="<?php echo $scoreType->name; ?>"
<?php if($edit == 1): if(strpos("{$eventType->score_types}", "{$scoreType->name}")): ?> checked<?php endif; endif; ?>>
<?php endforeach; ?>
</p>
<p>
<label for="is_disp">Display?</label>
<input type="checkbox" id="is_disp" name="is_disp" value="1"<?php if($edit == 1) { if($eventType->is_disp == 1) { echo " checked"; }} ?>>
</p>
<p>
<button type="submit" name="submit">Save</button><?php if($edit == 1): ?><a class="btn_cancel" href="index.php?con=event_types">done</a><?php endif; ?>
</p>
</fieldset>
</form>
</div><!-- end .admin_form -->
</div><!-- end #admin_ops_con -->
I think the problem is in the line
<?php if($edit == 1): if(strpos("{$eventType->score_types}", "{$scoreType->name}")): ?> checked<?php endif; endif; ?>>
if the entry is in the first position(index in the String is 0) strpos returns 0. PHP assumes that 0 equals false, so the first entry with the match with the index 0 will not be "checked".
this code should solve the problem (checking for false !==)
<?php if($edit == 1): if(strpos("{$eventType->score_types}", "{$scoreType->name}")!==false): ?> checked<?php endif; endif; ?>>
// Not tested since i dont have PHP installed on this machine. but will try to confirm this asap
Update:
Info strpos(...) return the index in the string. Counting starts by 0 so you would have to check explicitly for false (===false) oder (!==false) to be sure, that PHP doesnt treat the index 0 as false. here is a link to the manual (Link)
Related
I am learning PHP and am stuck right now. In a while loop, all the to-do items are displayed. Each of these elements has a delete button and a check button. The delete button works in every element, but the check button only works in the first one. The check button is to be used to check off an element. When the check button is pressed, an error message is displayed that this element could not be deleted. Only in the first element of course not. I can't find the error.
I suspect there is something wrong with the in the index
<?php
$todos = $conn->query("SELECT * FROM todos ORDER BY id DESC");
?>
<div class="show-todo-section">
<?php if($todos->rowCount() <= 0){ ?>
<div class="todo-item">
<div class="empty">
<img src="img/f.png" width="100%" />
<img src="img/Ellipsis.gif" width="80px">
</div>
</div>
<?php } ?>
<?php while($todo = $todos->fetch(PDO::FETCH_ASSOC)) { ?>
<div class="todo-item">
<form action="app/checked.php" method="POST">
<button class="check-box" value="<?php echo $todo['id']; ?>" name='checked' type="submit">Check</button>
</form>
<form action="app/delete.php" method="POST">
<button class="remove-to-do" value="<?php echo $todo['id']; ?>" name='delete' type="submit">x</button>
</from>
<?php if($todo['checked']){ ?>
<h2 class="checked"><?php echo $todo['title'] ?></h2>
<?php }else { ?>
<h2><?php echo $todo['title'] ?></h2>
<?php } ?>
<small>created: <?php echo $todo['date_time'] ?></small>
<?php for ($i = 1; $i <= $todo['coins']; $i++) {
echo "<img class='coins' src='img/coin.gif' width='40px' />";
} ?>
</div>
<?php } ?>
</div>
the checked.php
<?php
if (isset($_POST['checked'])) {
require '../db_conn.php';
$id = $_POST['checked'];
if(empty($id)){
header("Location: ../index.php?mess=errorChecked". $id);
}else{
$todos = $conn->prepare("SELECT id, checked FROM todos WHERE id=?");
$todos->execute([$id]);
$todo = $todos->fetch();
$uId = $todo['id'];
$checked = $todo['checked'];
$uChecked = $checked ? 0 : 1;
$res = $conn->query("UPDATE todos SET checked=$uChecked WHERE id=$uId");
header("Location: ../index.php?mess=successChecked");
$conn = null;
exit();
}
} else{
header("Location: ../index.php?mess=errorChecked");
}
I know that this question has been asked before, but I am struggling with selecting a default checkbox. I want the checkbox to be "Kenyan Used" by default as in the picture below:Selected "Kenyan Used. What i have tried is $taxonomy= $wpdb->get_results("SELECT term_id FROM par_taxonomy WHERE (taxonomy = 'condition' AND term_taxonomy_id= '181')");. Though I don't how the below code implements this, I know it is a for loop, but how do i modify it to work for my case?. Below is the specific code from where the taxonomies are fetched from:
<?php
if (!empty($modern_filter)){ $counter = 0;
foreach ($modern_filter as $modern_filter_unit) {
$counter++;
$terms = get_terms(array($modern_filter_unit['slug']), $args);
if (empty($modern_filter_unit['slider']) && $modern_filter_unit['slug'] != 'price') { /*<!--If its not price-->*/
//if ($modern_filter_unit['slug'] != 'price') { /* != 'price'<!--If its not price-->*/
/*First one if ts not image goes on another view*/
if ($counter == 1 and empty($modern_filter_unit['use_on_car_modern_filter_view_images'])
and !$modern_filter_unit['use_on_car_modern_filter_view_images']) {
if (!empty($terms)) { ?>
<div class="stm-accordion-single-unit <?php echo esc_attr($modern_filter_unit['slug']); ?>">
<a class="title" data-toggle="collapse"
href="#<?php echo esc_attr($modern_filter_unit['slug']) ?>" aria-expanded="true">
<h5><?php esc_html_e($modern_filter_unit['single_name'], 'motors'); ?></h5>
<span class="minus"></span>
</a>
<div class="stm-accordion-content">
<div class="collapse in content" id="<?php echo esc_attr($modern_filter_unit['slug']); ?>">
<div class="stm-accordion-content-wrapper">
<?php foreach ($terms as $term): ?>
<?php if (!empty($_GET[$modern_filter_unit['slug']]) and $_GET[$modern_filter_unit['slug']] == $term->slug) { ?>
<script type="text/javascript">
jQuery(window).load(function () {
var $ = jQuery;
$('input[name="<?php echo esc_attr($term->slug . '-' . $term->term_id); ?>"]').click();
$.uniform.update();
});
</script>
<?php } ?>
<div class="stm-single-unit">
<label>
<input type="checkbox"
name="<?php echo esc_attr($term->slug . '-' . $term->term_id); ?>"
data-name="<?php echo esc_attr($term->name); ?>"
/>
<?php echo esc_attr($term->name); ?>
</label>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
<?php } ?>
Thanks for the help in advance.
Assuming that this is the checkbox you want to do this for: Add an if statement to determine if the checkbox should be checked by default
<input type="checkbox"
name="<?php echo esc_attr($term->slug . '-' . $term->term_id); ?>"
data-name="<?php echo esc_attr($term->name); ?>"
<?php if($condition){?> checked <?php } ?>
/>
Replace $condition with something to determine if this is the checkbox you want checked by default. If you want all checkbox checked by default just add 'checked' inside the input tag without any if statements.
You need to add the checked attribute to your checkbox. You can check for the required term with an if statement. You need to add the following:
<?php if ($term->name == 'Kenyan Used') { echo ' checked'; } ?>
So then your input code looks like this:
<input type="checkbox"
name="<?php echo esc_attr($term->slug . '-' . $term->term_id); ?>"
data-name="<?php echo esc_attr($term->name); ?>"
<?php if ($term->name == 'Kenyan Used') { echo ' checked'; } ?> />
<?php echo esc_attr($term->name); ?>
Hope this helps!
I've started getting the following error message:
Parse error: syntax error, unexpected 'endforeach' (T_ENDFOREACH) in /home/paintpricescompa/public_html/wp-content/themes/compare/_includes/price-table.php on line 89
However, nothing has changed, i.e the file content etc. Below is the code, any help?
<?php
include(TEMPLATEPATH.'/_functions/get-options.php');
if(!function_exists('dont_cut_words')){
include(TEMPLATEPATH.'/_includes/utils.php');
}
$deeplinkInSameWindow = get_option('tz_price_comparison_table_open_deeplink_in_same_window');
$unicalPriceTableId = mt_rand();$current_blog_id = get_current_blog_id();
?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('.paginator-<?php echo $unicalPriceTableId; ?>').smartpaginator({ totalrecords: <?php echo $merchants_length; ?>, recordsperpage: <?php if (isset($tz_products_per_page) && is_numeric($tz_products_per_page)){ if($merchants_length >= $tz_products_per_page) { echo $tz_products_per_page; } else { echo $merchants_length; } } else { echo "10";}; ?>, datacontainer: 'price-comparison-table-<?php echo $unicalPriceTableId; ?>', dataelement: 'tr', initval: 0, next: 'Next', prev: 'Prev', first: 'First', last: 'Last', theme: 'black' });
});
</script>
<table id="price-comparison-table-<?php echo $unicalPriceTableId; ?>" class="single-product prices-table" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th> </th>
<th><?php _e('Product','framework'); ?></th>
<th><?php _e('Retailer','framework'); ?></th>
<th class="thead-price sort-numeric"><div><?php _e('Price','framework'); ?></div></th>
</tr>
</thead>
<tbody>
<?php foreach($merchants as $merchant): ?>
<tr>
<td class="image-column">
<?php if($merchant->feed_product_image != ''): ?>
<img src="<?php echo str_replace('&','&',$merchant->feed_product_image); ?>" alt="<?php echo $merchant->feed_product_name; ?>" />
<?php endif; ?>
</td>
<td class="product-column">
<span class="product-title"><?php echo stripslashes($merchant->feed_product_name); ?></span><br />
<?php echo dont_cut_words($merchant->feed_product_desc,100); // echo substr(strip_tags($merchant->feed_product_desc),0,100); ?><br />
<?php if($merchant->voucher != ''): ?>
<span class="product-voucher">
<?php _e('VOUCHER CODE:','framework'); ?> <?php echo $merchant->voucher ?>
</span>
<?php endif; ?>
</td>
<td class="merchant-column"> <?php if($current_blog_id == 1){ $uploadDirCategoriesAbsolute = ABSPATH.'wp-content/uploads/compare/merchants/'; $uploadDirCategories = '/wp-content/uploads/compare/merchants/'; } else { // For WP multisite installation $uploadDirCategoriesAbsolute = ABSPATH.'wp-content/uploads/compare/merchants/'.$current_blog_id.'/'; $uploadDirCategories = '/wp-content/uploads/compare/merchants/'.$current_blog_id.'/'; } ?>
<?php if($merchant->image != "" && file_exists($uploadDirCategoriesAbsolute.$merchant->image)): ?>
<a class="image" href="<?php echo str_replace('&','&',$merchant->deeplink); ?>" rel="nofollow"><img src="<?php echo home_url().$uploadDirCategories.$merchant->image; ?>" alt="<?php echo stripslashes($merchant->name); ?>" title="" /></a>
<?php else: ?>
<?php echo stripslashes($merchant->name) ?><br />
<?php endif; ?>
<small><?php _e('Last update:','framework'); echo ' '.date((get_option('tz_date_format') != '' ? get_option('tz_date_format') : 'd-m-Y H:i'),$merchant->last_update); ?></small>
</td>
<td class="price-column">
<span class="product-price">
<?php
$product_price = number_format($merchant->price,2,'.','');
if(compare_get_currency('position') == "left"){
echo str_replace(array("\r\n", "\r", "\n", " "), "", compare_get_currency('symbol')).$product_price;
}
else
{
echo $product_price.str_replace(array("\r\n", "\r", "\n", " "), "", compare_get_currency('symbol'));
}
?>
</span><br />
<?php
if($merchant->shipping != '') {
$merchant->shipping = str_replace(',','.',$merchant->shipping);
if(is_numeric($merchant->shipping)) {
_e('Delivery:','framework');
echo ' ';
$merchant->shipping = number_format($merchant->shipping,2,'.','');
if(compare_get_currency('position') == "left"){
echo str_replace(array("\r\n", "\r", "\r", " "), "", compare_get_currency('symbol')).$merchant->shipping;
}
else
{
echo $merchant->shipping.str_replace(array("\r\n", "\r", "\r", " "), "", compare_get_currency('symbol'));
}
} else {
echo '<a class="tiptip" title="'.$merchant->shipping.'">';
_e('Delivery','framework');
echo '</a>';
}
echo '<br />';
}
?>
<a class="zum_shop" <?php echo ((isset($deeplinkInSameWindow) && $deeplinkInSameWindow == 'true')) ? "" : "target='_blank'" ?> rel="nofollow" href="<?php echo str_replace('&','&',$merchant->deeplink); ?>"><?php echo (isset($tz_buy_button_text) && $tz_buy_button_text != '') ? stripslashes($tz_buy_button_text) : __('BUY NOW','framework'); ?></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<input type="text" class="merchants_length_input" style="display:none" value="<?php echo $merchants_length; ?>" />
<input type="text" class="products_per_page_input" style="display:none" value="<?php if (isset($tz_products_per_page) && is_numeric($tz_products_per_page)){ if($merchants_length >= $tz_products_per_page) { echo $tz_products_per_page; } else { echo $merchants_length; } } else { echo "10";}; ?>" />
<div class="paginator-<?php echo $unicalPriceTableId; ?>" style="margin: auto;">
</div>
Remember when you put the below comment on the script?
// For WP multisite installation
It just commented out the closing brace for an else block in your code. Thats triggering the error.
Its on line #41
<td class="merchant-column"> <?php if($current_blog_id == 1){ $uploadDirCategoriesAbsolute = ABSPATH.'wp-content/uploads/compare/merchants/'; $uploadDirCategories = '/wp-content/uploads/compare/merchants/'; } else { // For WP multisite installation $uploadDirCategoriesAbsolute = ABSPATH.'wp-content/uploads/compare/merchants/'.$current_blog_id.'/'; $uploadDirCategories = '/wp-content/uploads/compare/merchants/'.$current_blog_id.'/'; } ?>
There is syntax error in
<td class="merchant-column"> <?php if($current_blog_id == 1){ $uploadDirCategoriesAbsolute = ABSPATH.'wp-content/uploads/compare/merchants/'; $uploadDirCategories = '/wp-content/uploads/compare/merchants/'; } ?>
<?php if($merchant->image != "" && file_exists($uploadDirCategoriesAbsolute.$merchant->image)): ?>
<a class="image" href="<?php echo str_replace('&','&',$merchant->deeplink); ?>" rel="nofollow"><img src="<?php echo home_url().$uploadDirCategories.$merchant->image; ?>" alt="<?php echo stripslashes($merchant->name); ?>" title="" /></a>
<?php else: ?>
<?php echo stripslashes($merchant->name) ?><br />
<?php endif; ?>
<small><?php _e('Last update:','framework'); echo ' '.date((get_option('tz_date_format') != '' ? get_option('tz_date_format') : 'd-m-Y H:i'),$merchant->last_update); ?></small>
</td>
No need to use else part if nothing will happen in this case.
Just replace this div (corrected) and run your code.
I have overriden the following core template in checkout process shipping section.
app/design/frontend/base/default/template/checkout/onepage/shipping_method/available.phtml
I have two shipping methods. First one is 'Deliveryrate'. In this module I have overriden the above template file. Second shipping module is 'Store-Pickup'. But when I load the 'Store-Pickup' always loading the Deliveryrate'. I couldn't find the error. Please any suggestions?
following is the edited template file.
<?php if (!($_shippingRateGroups = $this->getShippingRates())): ?>
<p><?php echo $this->__('Sorry, no quotes are available for this order at this time.') ?></p>
<?php else: ?>
<dl class="sp-methods">
<?php $shippingCodePrice = array(); ?>
<?php $_sole = count($_shippingRateGroups) == 1;
foreach ($_shippingRateGroups as $code => $_rates): ?>
<?php
$helper = Mage::helper('deliveryrate');
$isFlorist = $helper->IsCollectFromFlorist();
if(!$isFlorist)
{
?>
<?php if($code == 'deliveryrate') // If the shipping method is deliveryshipping
{?>
<?php
// Get deliveryrate option details.
$all_options = Mage::getModel('deliveryrate/alloptions')->getCollection();
?>
<dt><?php echo $this->getCarrierName($code) ?></dt> <?php //header ?>
<dd>
<ul>
<table id="tbl-delivery-shipping">
<tbody>
<tr>
<td><label for="delivery-options" class="required" style="float:right;"><em>*</em>Delivery Time :</label></td>
<td>Option 1 - Standard Delivery
</tr>
<tr>
<td></td>
<td>
<?php $_sole = $_sole && count($_rates) == 1;
foreach ($_rates as $_rate): ?>
<?php
$option = $_rate->getCode();
$optionArray = explode( '_', $option );
$array_last_index = count($optionArray)-1;
$delivery_option = $optionArray[$array_last_index-1];
if($delivery_option == 1)
{
?>
<li>
<?php $shippingCodePrice[] = "'".$_rate->getCode()."':".(float)$_rate->getPrice(); ?>
<li>
<?php if ($_rate->getErrorMessage()): ?>
<ul class="messages">
<li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li>
</ul>
<?php else: ?>
<?php if ($_sole) : ?>
<span class="no-display">
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>" checked="checked" />
</span>
<?php else: ?>
<?php // radio button ?>
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
<?php if ($_rate->getCode() === $this->getAddressShippingMethod()): ?>
<script type="text/javascript">
//<![CDATA[
lastPrice = <?php echo (float)$_rate->getPrice(); ?>;
//]]>
</script>
<?php endif; ?>
<?php endif; ?>
<?php // option name ?>
<label for="s_method_<?php echo $_rate->getCode() ?>">
<?php $option_name = $_rate->getMethodTitle();
$optionNameArray = explode( '(', $option_name );
if(count($optionNameArray)>1)
{
echo $optionNameArray[0];
?>
<br>
<?php
echo '('.$optionNameArray[1];
}
else
{
echo $optionNameArray[0];
}
?>
<?php // echo $_rate->getMethodTitle() ?>
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
<?php // echo $_excl; ?>
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
<?php endif; ?>
</label>
<?php
$carrier = Mage::getModel('shipping/config')->getCarrierInstance($code);
if($carrier->getFormBlock()){
$block = $this->getLayout()->createBlock($carrier->getFormBlock());
$block->setMethodCode($code);
$block->setRate($_rate);
$block->setMethodInstance($carrier);
echo $block->_toHtml();
}
?>
<?php endif ?>
</li>
<?php } ?>
<?php endforeach; ?>
</td>
</tr>
<tr>
<td><br></td>
<td></td>
</tr>
<tr>
<td></td>
<td>Option 2 - specific Time
<label style="font-size: 12px;font-weight:normal;color:silver;">(There will be an additional delivery charge for specific delivery time.)</label>
</tr>
<tr>
<td></td>
<td>
<ul>
<?php $_sole = $_sole && count($_rates) == 1;
foreach ($_rates as $_rate): ?>
<?php
$option = $_rate->getCode();
$optionArray = explode( '_', $option );
$array_last_index = count($optionArray)-1;
$delivery_option = $optionArray[$array_last_index-1];
if($delivery_option == 2)
{
?>
<?php $shippingCodePrice[] = "'".$_rate->getCode()."':".(float)$_rate->getPrice(); ?>
<li style="width:250px;float:left;">
<?php if ($_rate->getErrorMessage()): ?>
<ul class="messages">
<li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li>
</ul>
<?php else: ?>
<?php if ($_sole) : ?>
<span class="no-display">
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>" checked="checked" />
</span>
<?php else: ?>
<?php // radio button ?>
<?php
foreach($all_options as $opt)
{
$data = $opt->getData();
if($current_category_id == 12)//Cake
{$kk = trim(date("Y-m-d", $tomorrow));
if(trim(date("Y-m-d", $tomorrow)) == trim($order_delivery_date))
{
if(strcmp(trim($_rate->getMethodTitle()),trim($data['delivery_type'])) == 0)
{
$start_time = $data['start_time'];
$end_time = $data['end_time'];
if($delivery_start_time < $start_time)// || (($start_time < $delivery_start_time) && ($delivery_start_time < $end_time)))
{
// Enable option.
?>
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
<?php
}
else
{
?>
<input disabled="disabled" name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
<?php
}
}
}
else
{
?>
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
<?php
break;
}
}
else //Rest all products
{
if(trim(date("Y-m-d")) == trim($order_delivery_date))//today's delivery
{
//check the server time to enable option
if(strcmp(trim($_rate->getMethodTitle()),trim($data['delivery_type'])) == 0)
{
$start_time = $data['start_time'];
$end_time = $data['end_time'];
if($server_time < $start_time)// || (($start_time < $server_time) && ($server_time < $end_time)))
{
// Enable option.
?>
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
<?php
}
else
{
?>
<input disabled="disabled" name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
<?php
}
}
}
else
{
?>
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
<?php
break;
}
}
}//foreach
?>
<?php if ($_rate->getCode() === $this->getAddressShippingMethod()): ?>
<script type="text/javascript">
//<![CDATA[
lastPrice = <?php echo (float)$_rate->getPrice(); ?>;
//]]>
</script>
<?php endif; ?>
<?php endif; ?>
<?php // option name ?>
<label for="s_method_<?php echo $_rate->getCode() ?>">
<?php $option_name = $_rate->getMethodTitle();
$optionNameArray = explode( '(', $option_name );
if(count($optionNameArray)>1)
{
echo $optionNameArray[0];
?>
<br>
<?php
echo '('.$optionNameArray[1];
}
else
{
echo $optionNameArray[0];
}
?>
<?php // echo $_rate->getMethodTitle() ?>
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
<?php // echo $_excl; ?>
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
<?php endif; ?>
</label>
<?php
$carrier = Mage::getModel('shipping/config')->getCarrierInstance($code);
if($carrier->getFormBlock()){
$block = $this->getLayout()->createBlock($carrier->getFormBlock());
$block->setMethodCode($code);
$block->setRate($_rate);
$block->setMethodInstance($carrier);
echo $block->_toHtml();
}
?>
<?php endif ?>
</li>
<?php } ?>
<?php endforeach; ?>
</ul>
<div style="clear: both;"></div>
</td>
<tr>
<td><br></td>
<td></td>
</tr>
<tr>
<td style="text-align: right;"><label >Special<br> Instruction : </label></td>
<td><textarea class="textarea-delivery" rows="3" cols="50" name="shipping_deliveryrate[special_instructions]" id="shipping_deliveryrate[special_instructions]" cols="20" rows="4"></textarea></td>
</tr>
<tr>
<td></td>
<td><label style="font-size: 12px;font-weight:normal;font-style:italic;color:silver;">Enter any special instructions or notes about this order<br>
Example: "Call the recipient before the delivery. Try to deliver before 4.00pm"
</label></td>
</tr>
<tr>
<td><br></td>
<td></td>
</tr>
<tr>
<td></td>
<td style="text-align: right;">
<div style="width: 430px;padding-right: 83px;padding-bottom: 4px;">
<div style="float: left;width: 322px;height: 30px;"><a href="#" style="text-decoration: none;"><label style="font-size: 10px;font-weight:normal;color: #839821;">If you need to type our personal message<br>
in Sinhala or Tamil, please use relevant keyboard here</label></a>
</div>
<div style="width: 108px;height: 30px;float: left;padding-bottom: 4px;padding-top: 8px;">
<input type="button" name="sinhala_keyboard" id="sinhala_keyboard" class="button-checkout-language" value="Sinhala" onclick="opensinhalakeyboard();" />
<input type="button" name="tamil_keyboard" id="tamil_keyboard" class="button-checkout-language" value="Tamil" onclick="opentamilkeyboard();" />
</div>
</div>
</td>
</tr>
<tr>
<td><label style="float:right;">Personel <br>Message : </label></td>
<td><textarea class="textarea-delivery" rows="3" cols="50" name="shipping_deliveryrate[msg]" id="shipping_deliveryrate[msg]" cols="20" rows="4"></textarea></td>
</tr>
<tr>
<td></td>
<td><label style="font-size: 12px;font-weight:normal;font-style:italic;color:silver;">Your message will be hand written on a white card & sent with the gift item.</label></td>
</tr>
</tbody>
</table>
</li>
</ul>
</dd>
<?php
break;
}
}//not florist
else
{
// if florist selected
if($code == 'pickup') // If the shipping method is pickup
{
?>
<dt><?php echo $this->getCarrierName($code) ?></dt>
<dd>
<ul>
<?php $_sole = $_sole && count($_rates) == 1; foreach ($_rates as $_rate): ?>
<?php $shippingCodePrice[] = "'".$_rate->getCode()."':".(float)$_rate->getPrice(); ?>
<li>
<?php if ($_rate->getErrorMessage()): ?>
<ul class="messages"><li class="error-msg"><ul><li><?php echo $_rate->getErrorMessage() ?></li></ul></li></ul>
<?php else: ?>
<?php if ($_sole) : ?>
<span class="no-display"><input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>" checked="checked" /></span>
<?php else: ?>
<input name="shipping_method" type="radio" value="<?php echo $_rate->getCode() ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio"/>
<?php if ($_rate->getCode() === $this->getAddressShippingMethod()): ?>
<script type="text/javascript">
//<![CDATA[
lastPrice = <?php echo (float)$_rate->getPrice(); ?>;
//]]>
</script>
<?php endif; ?>
<?php endif; ?>
<label for="s_method_<?php echo $_rate->getCode() ?>"><?php echo $_rate->getMethodTitle() ?>
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
<?php echo $_excl; ?>
<?php if ($this->helper('tax')->displayShippingBothPrices() && $_incl != $_excl): ?>
(<?php echo $this->__('Incl. Tax'); ?> <?php echo $_incl; ?>)
<?php endif; ?>
</label>
<?php
$carrier = Mage::getModel('shipping/config')->getCarrierInstance($code);
if($carrier->getFormBlock()){
$block = $this->getLayout()->createBlock($carrier->getFormBlock());
$block->setMethodCode($code);
$block->setRate($_rate);
$block->setMethodInstance($carrier);
echo $block->_toHtml();
}
?>
<?php endif ?>
</li>
<?php endforeach; ?>
</ul>
</dd>
<?php
break;
}
} ?>
<?php endforeach; ?>
</dl>
<script type="text/javascript">
//<![CDATA[
<?php if (!empty($shippingCodePrice)): ?>
var shippingCodePrice = {<?php echo implode(',',$shippingCodePrice); ?>};
<?php endif; ?>
$$('input[type="radio"][name="shipping_method"]').each(function(el){
Event.observe(el,'click', function(){
if (el.checked == true) {
var getShippingCode = el.getValue();
<?php if (!empty($shippingCodePrice)): ?>
var newPrice = shippingCodePrice[getShippingCode];
if (!lastPrice) {
lastPrice = newPrice;
quoteBaseGrandTotal += newPrice;
}
if (newPrice != lastPrice) {
quoteBaseGrandTotal += (newPrice-lastPrice);
lastPrice = newPrice;
}
<?php endif; ?>
checkQuoteBaseGrandTotal = quoteBaseGrandTotal;
return false;
}
});
});
//]]>
jQuery(document).ready(function(){
hideShippingAll();
jQuery('input[type="radio"][name="shipping_method"]').click(function(){
hideShippingAll();
var code = jQuery(this).val();
if(jQuery(this).is(':checked')){
showShipping(code);
}
});
jQuery('input[type="radio"][name="shipping_method"]').each(function(){
var code = jQuery(this).val();
if(jQuery(this).is(":checked")){
showShipping(code);
}
});
});
function showShipping(code){
if(jQuery('#'+'shipping_form_'+code).length != 0){
jQuery('#'+'shipping_form_'+code).show();
jQuery(this).find('.required-entry').attr('disabled','false');
}
}
function hideShippingAll(){
jQuery('input[type="radio"][name="shipping_method"]').each(function(){
var code = jQuery(this).val();
jQuery('#'+'shipping_form_'+code).hide();
jQuery(this).find('.required-entry').attr('disabled','true');
});
}
function open_in_new_tab(url)
{
window.open(url, '_blank');
window.focus();
}
</script>
<?php endif; ?>
I found the solution.
Both of the shipping methods have same event observer names. That is why it always execute one observer. So changing the event observer names worked
I have several quantity boxes next to products so a user can input what quantity they want of a certain product.
The setup uses a step by step process using Jquery with the first step made up of checkboxes, the second made up of quantity inputs (where I need the help!) and the final step shows what has been selected... on submit it all gets emailed to me.
Step 1 with checkboxes is complete (with a lot of help from #Beetroot-Beetroot -Step by step checkbox process with summary of selections). Step 2 is where I need the help, how can I show the user quantity inputs on the summary page?
Here's the HTML:
<form id="customisesystem" method="post" action="">
<div id="first-step">
<div class="steps">
<p><b>Step 1 of 3</b></p>
</div>
<div class="progress-buttons"></div>
<div class="clear"></div>
<div id="customise-area">
<div id="customise-title">
<p><b>1. Hardware & software options</b> <span>Please choose one or more of the following</span></p>
</div>
<div id="customise-area">
<?php $posts = get_field('options');
if( $posts ):
$items = 0;
foreach( $posts as $post): // variable must be called $post (IMPORTANT)
setup_postdata($post); ?>
<div class="custom-option">
<p><b>
<?php the_title(); ?>
</b></p>
<br />
<div> <?php echo the_content(); ?> </div>
<?php $counter = 1; while(the_repeater_field('images')): ?>
<?php if($counter <= 1) { ?>
<img width="180" height="136" src="<?php the_sub_field('image'); ?>" alt="<?php the_title(); ?>" />
<?php } ?>
<?php $counter++; endwhile; ?>
<p>
<input type="checkbox" name="hardware[]" value="<?php the_title(); ?>">
Select</p>
<div class="clear"></div>
</div>
<?php $items++; endforeach;
wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
endif; ?>
</div>
</div>
</div>
<!-- end first-step -->
<div id="second-step">
<div class="steps">
<p><b>Step 2 of 3</b></p>
</div>
<div class="progress-buttons"></div>
<div class="clear"></div>
<div id="customise-area">
<div id="customise-title">
<p><b>2. Accessories</b> <span>Please choose one or more of the following</span></p>
</div>
<div id="customise-area">
<?php $posts = get_field('accessories');
if( $posts ):
$items = 0;
foreach( $posts as $post): // variable must be called $post (IMPORTANT)
setup_postdata($post); ?>
<?php if ($items&1) { ?>
<div class="custom-option">
<p><b>
<?php the_title(); ?>
</b></p>
<br />
<div> <?php echo the_content(); ?> </div>
<?php $counter = 1; while(the_repeater_field('images')): ?>
<?php if($counter <= 1) { ?>
<img width="180" height="136" src="<?php the_sub_field('image'); ?>" alt="<?php the_title(); ?>" />
<?php } ?>
<?php $counter++; endwhile; ?>
<p style="clear:right;float:right;width:180px;">
<?php if(get_field('sizes')) { ?>
<?php while(the_repeater_field('sizes')) { ?>
<input type="text" name="quantity[]" style="width:15px;" value="0">
<?php echo the_sub_field('size'); ?><br />
<input type="hidden" name="product[]" value="<?php echo the_title(); ?> - <?php echo the_sub_field('size'); ?>">
<?php } ?>
<?php } else { ?>
<input type="text" name="quantity[]" style="width:15px;" value="">
<?php echo the_sub_field('size'); ?><br />
<input type="hidden" name="product[]" value="<?php echo the_title(); ?>">
<?php } ?>
</p>
<div class="clear"></div>
</div>
<?php } else { ?>
<div class="custom-option">
<p><b>
<?php the_title(); ?>
</b></p>
<br />
<div> <?php echo the_content(); ?> </div>
<?php $counter = 1; while(the_repeater_field('images')): ?>
<?php if($counter <= 1) { ?>
<img width="180" height="136" src="<?php the_sub_field('image'); ?>" alt="<?php the_title(); ?>" />
<?php } ?>
<?php $counter++; endwhile; ?>
<p style="clear:right;float:right;width:180px;">
<?php if(get_field('sizes')) { ?>
<?php while(the_repeater_field('sizes')) { ?>
<input type="text" name="quantity[]" style="width:15px;" value="0">
<?php echo the_sub_field('size'); ?><br />
<input type="hidden" name="product[]" value="<?php echo the_title(); ?> - <?php echo the_sub_field('size'); ?>">
<?php } ?>
<?php } else { ?>
<input type="text" name="quantity[]" style="width:15px;" value="">
<?php echo the_sub_field('size'); ?><br />
<input type="hidden" name="product[]" value="<?php echo the_title(); ?>">
<?php } ?>
</p>
<div class="clear"></div>
</div>
<?php } ?>
<?php $items++; endforeach;
wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
endif; ?>
</div>
</div>
</div>
<!-- end second-step -->
<div id="third-step">
<div class="steps">
<p><b>Step 3 of 3</b></p>
</div>
<div class="progress-buttons"></div>
<div class="clear"></div>
<div id="customise-area-3">
<p>Summary</p>
<div id="customise-area-3-child">
<input type="submit" name="submit" id="submit" value="submit" />
</div>
</div>
</div>
<!-- end third-step -->
</form>
Here's the Jquery:
jQuery(document).ready(function( $ ) {
//Create nav wrapper
var $nav = $('<div/>').addClass('prev-next');
//Create Prev button, attach click handler and append to nav wrapper
$('<a class="prev" href="#">Back</a>').on('click', function () {
$(this).closest(".step").hide().prev(".step").show();
}).prependTo($nav);
//Create Next button, attach click handler and append to nav wrapper
$('<a class="next" href="#">Next</a>').on('click', function () {
$('.summary_text').html(makeSummary());
var $step = $(this).closest(".step");
if (validate($step)) {
$step.hide().next(".step").show();
}
}).appendTo($nav);
//In one long jQuery chain ...
//* prepend nav to each step div
//* hide all steps except the first
//* convert first 'Back' link and last 'Next' link to spans.
var $steps = $(".step").prepend($nav).hide()
.filter(":first").show().find("a.prev").after('Back').remove().end().end()
.filter(":last").find("a.next").after('').remove().end().end();
//Set step titles
$steps.each(function (i, step) {
$(step).find(".step-title").text('Step ' + (i + 1) + ' of ' + $steps.length);
});
$('a.back-to-product').click(function(){
$(".customise").hide();
$(".entire_product").show();
});
//Unfortunately, hidden form elements are not inlcuded in the submission,
//so all steps must be shown before the form is submitted.
var $submitButton = $("input[name='submit']").on('submit', function () {
$steps.show();
return true;
});
function validate($step) {
//var valid = false;
var valid = true; //for debugging
//Perform validation
switch ($step.index(".step")) { //index-origin is zero
case 0:
//Validate step 1 here
//if valid, set `valid` to true
break;
case 1:
//Validate step 2 here
//if valid, set `valid` to true
break;
case 2:
//No validatation required
break;
}
return valid; //Important - determines behaviour after validate() returns.
}
function makeSummary() {
var summary = [];
$steps.not(":last").each(function (i, step) {
$step = $(step);
summary.push('<p><b>' + $step.data('name') + '</b></p>');
var $ch = $step.find('input[type="checkbox"]:checked');
if (!$ch.length) {
summary.push('<p>No items selected</p><br />');
} else {
$ch.each(function (i, ch) {
summary.push('<p>' + $(ch).val() + '</p><br />');
});
}
});
return summary.join('');
}
});
First, make the quantity[] and product[] fields more readily selectable by hard-coding class="quantity" and class="product" in the HTML.
<input type="text" name="quantity[]" class="quantity" style="width:15px;" value="0">25 cm²<br />
<input type="hidden" name="product[]" class="product" value="Equipment Electrode Set - 25 cm²">
Here's the javascript :
function makeSummary() {
var summary = [];
$steps.not(":last").each(function (i, step) {
$step = $(step);
summary.push('<p><b>' + $step.data('name') + '</b></p>');
var $ch = $('input[type="checkbox"]:checked', $step);
var $qty = $('input.quantity', $step).filter(function() {
return this.value !== '0';
});
var $selected = $ch.add($qty);//jQuery collection of checkeboxes, or quantity fields, or a mixture of both.
if (!$selected.length) {
summary.push('<p>No items selected</p><br />');
} else {
$selected.each(function (i, s) {
var $s = $(s);
var prefix = ($s.hasClass('quantity')) ? ($s.nextAll("input.product").val() + ' : ') : '';
summary.push('<p>' + prefix + $s.val() + '</p><br />');
});
}
});
return summary.join('');
}
By doing it this way, the function remains general with regard to the number of steps, but also with regard to the composition of each step; it will handle completely specialized "checkbox step(s)" and "quantity step(s)", and (should you ever have the need) mixed "checkbox/quantity step(s)". In every case, the selected items will be summarized in their original DOM order.
DEMO