I am working on cakephp 1.3..
i have button and value displaying inside button coming from database.
I want to show arrow icon on my active button only..
now the active arrow icon is displaying in all button...inside forloop.
plz help me to do this..
below is my code
<?php
foreach($modes as &$mo)
{
$temp = "Road Vs "; $mo = strtolower($mo);
?>
<li class="active">
<input name="data[Customer][mode]" class="railbtn" type="submit" id="mode" value="<?php echo $temp.$mo; ?>">
<span class="arrow">
<?php echo $this->Html->image('red_arrow.png', array('alt' => '')); ?>
</span>
</li>
<?php } ?>
You should add a condition in your for loop
Like this
<?php
// you need to send button unique name to controller
foreach($modes as &$mo)
{
$temp = "Road Vs "; $mo = strtolower($mo); ?>
<li class="<?php echo ($mo == $selectedUniqueButtonID) ? 'active' : '' ?>">
<input name="data[Customer][mode]" class="railbtn" type="submit" id="mode" value="<?php echo $temp.$mo; ?>">
<?php if($mo == $selectedUniqueButtonID){ ?>
<span class="arrow">
<?php echo $this->Html->image('red_arrow.png', array('alt' => '')); ?>
</span>
<?php } ?>
</li>
<?php
} ?>
Controller code
$selectedUniqueButtonID = $this->data['Customer']['mode'];
$this->set('selectedUniqueButtonID',$selectedUniqueButtonID);
Related
The final lists are looking like this and by clicking the green button I need to add class only to the list above. Only PHP is allowed
Click here
<ul class='wrapper'>
<?php foreach ($items as $item) : ?>
<li class="note" id='<?= $item['id'] ?>'>
<div class="details">
<p><?= $item['title']."<span class='currentDate'>".$item['currentDate']."</span>"?></p>
<p class ="importance"><?= $item['importance'] ?></p>
<div class="border"></div>
<span><?= $item['text'] ?></span>
</div>
<div class="bottom-content">
<span>Do: <?= date('d.m.Y', strtotime($item['date'])) ?></span>
<form method="post">
<button name="doneButton" value='<?= $item['id'] ?>' type="submit">✅</button>
</form>
<?php
if(isset($_POST['doneButton'])) {
//
//
}
?>
<form method="post" >
<button value="<?= $item['id'] ?>" name="deleteButton" type="submit">🗑️</button>
</form>
<?php
if(isset($_POST['deleteButton'])){
db_remove_note($_POST['deleteButton']);
header("Location: list-notes.php");
}
?>
</div>
</li>
<?php endforeach; ?>
</ul>
I want to add a class to li with the specific ID ($item['id']) using that doneButton. I need to use PHP only, with no JavaScript or MySQL.
Just add the condition to the li class attribute. I’d personally use a ternary operator as below to add MYNEWCLASS on the condition that $_POST['doneButton']) is set:
<li class="note<?=(isset($_POST['doneButton'])?" MYNEWCLASS":"");?>" id='<?= $item['id'] ?>'>
EDIT: To select an LI by a certain ID:
<?php
<ul class='wrapper'>
<?php foreach ($items as $item) : ?>
<?php
$class = ""; //Declare an empty $class
if (isset($_POST['doneButton']) && $_POST['doneButton'] == $item['id']){
// If $_POST['doneButton'] is set, and $_POST['doneButton'] is equal to the id of the current iteration then set $class to "MYNEWCLASS"
$class = " MYNEWCLASS"; //THE SPACE IS IMPORTANT
}
?>
<li class="note<?=$class;?>" id='<?= $item['id'] ?>'>
<div class="details">
<p><?= $item['title']."<span class='currentDate'>".$item['currentDate']."</span>"?></p>
<p class ="importance"><?= $item['importance'] ?></p>
<div class="border"></div>
<span><?= $item['text'] ?></span>
</div>
<div class="bottom-content">
<span>Do: <?= date('d.m.Y', strtotime($item['date'])) ?></span>
<form method="post">
<button name="doneButton" value='<?= $item['id'] ?>' type="submit">✅</button>
</form>
<form method="post" >
<button value="<?= $item['id'] ?>" name="deleteButton" type="submit">🗑️</button>
</form>
<?php
if(isset($_POST['deleteButton'])){
db_remove_note($_POST['deleteButton']);
header("Location: list-notes.php");
}
?>
</div>
</li>
<?php
endforeach;
?>
</ul>
I have some working PHP code and I have recently added a button that allows the user to download the image form the root directory, in the database we put the file name e.g. example.png / example.jpeg and when the user clicks download it opens the image in a new tab
what we need is: if the [proof] is= NULL , the download button disables, otherwise it will be enabled and they can click the button
<?php
// output data of each row
while($row=mysqli_fetch_assoc($designresult)) {
?>
<div class="card mb-4 box-shadow"><div class="card-header">
<h4 class="my-0 font-weight-normal">Job Reference: <?php echo $row["jobRef"]; ?></h4>
</div>
<div class="card-body">
<p><b>Company Name:</b><br> <?php echo $row["companyName"]; ?> </p>
<p><b>Requested:</b><br> <?php echo $row["dateReq"]; ?> </p>
<p><b>Request By:</b><br> <?php echo $row["yourName"]; ?> </p>
<p><b>Graphic Type:</b><br> <?php echo $row["graphicType"]; ?> </p>
<p><b>Double Sided:</b><br> <?php echo $row["doubleS"]; ?> </p>
<p><b>Design Info:</b><br> <?php echo $row["info"]; ?> </p>
<p><b>Purpose:</b><br> <?php echo $row["purpose"]; ?> </p>
<p><b>Proof:</b><br> <?php echo $row["approved"]; ?> </p>
<p><b>Proof Date:</b><br> <?php echo $row["appDate"]; ?> </p>
<a class="btn btn-success" target="_blank" href="<?php echo IMAGE_DIR . $row['proof']; ?>">Download</a>
</div>
</div>
<?php
}
?>
To my knowledge the link tag does not have a "disabled" attribute. But you can "disable" the link by removing the href attribute.
Something like this: It checks if $row['proof'] has some value (by negating the empty), then it prints out the href if result is true.
<a class="btn btn-success" target="_blank" <?php if(!empty($row['proof'])): ?> href="<?php echo IMAGE_DIR . $row['proof']; ?>" <?php endif; ?> >Download</a>
Or maybe better: Check if variable is empty and give the user a hint that it's not available. I think this is the better solution, because then your users will know what's going on.
<?php if(empty($row['proof'])): ?>
<span>No proof available</span>
<?php else: ?>
<a class="btn btn-success" target="_blank" href="<?php echo IMAGE_DIR . $row['proof']; ?>">
Download
</a>
<?php endif; ?>
<a
class="btn btn-success"
target="_blank"
<?php if(empty($row['proof'])) echo "disabled"; ?>
href="<?php if(!empty($row['proof'])) echo IMAGE_DIR . $row['proof']; ?>">
Download
</a>
try above code. and add disabled class using this condition
<?php
$state = (empty($row['proof'])) ? "disabled='disabled'" : "";
$class = (empty($row['proof'])) ? "disabled" : "";
?>
<a class="btn btn-success <?php echo $class; ?>" target="_blank" href="<?php echo IMAGE_DIR . $row['proof']; ?>" <?php echo $state; ?>>Download</a>
To disabled the button, you need to use disabled HTML attribute. The code above checks $row['proof'] == NULL. If this statement is true it prints disabled = "disabled" in the button element and it isn't true, it prints nothing.
Assuming that you are using bootstrap, .disabled will grayed out the button.
I have a radio button. I have 2 radio button for different use, one is for displaying the ukuran and the other is for displaying the jenis. The radio button value is generated from database. I want to get the radio button value then when both of them is click I want to search to database with that certain value. Can anyone help me?
I try this
<ul class="list">
<li>
<a class="active" href="#">
<span>Jenis Produk </span>
</a>
</li>
<?php
foreach($jenis as $jns){
?>
<input type="radio" id="jenis_produk" name="jenis_produk" value="<?php echo $jns['jenis_id'];?>">
<label><?php echo $jns['jenis_produk'];?></label><br>
<?php
}
?>
<li>
<span>Ukuran</span>
</li>
<?php
foreach($ukuran as $size){
?>
<input type="radio" id="ukuran_produk" name="ukuran_produk" value="<?php echo $size['ukuran_id'];?>">
<label><?php echo $size['size'];?></label><br>
<?php
}
?>
</ul>
Thank You :)
You can simply use following in the controller to get values
$jenis = $this->input->post("jenis_produk");
$ukuran = $this->input->post("ukuran_produk");
Then pass it to a model and
$sets = array("jenis" => $jenis,
"ukuran" => $ukuran);
$result = $this->db->where($sets)->get("table_name")->result_array();
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 got some code while searching for hide add to cart button at category products but i am not able to set this below code to my given List.phtml, Please guide me.
Now we will hide the ‘Add to Cart’ button on category list page. Open /app/design/frontend/default/themeXXX/template/catalog/product/list.phtml file and look for the following code:
<?php
if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
echo '<span class="login_for_details" style="float:left"><strong>Login to Add to Cart</strong></span>';
} else { ?>
My website list.phtml
<?php if ($product->isSaleable()) : ?>
<?php if ( !($product->getTypeInstance(true)->hasOptions($product) || $product->isGrouped()) ) : ?>
<?php if(!Mage::getStoreConfig("ajaxcart/addtocart/enablecategory", $code)):?>
<form id="addtocart_form_<?php echo $_product->getId(); ?>" action="<?php echo $this->getAddToCartUrl($_product) ?>" method="post">
<input type="hidden" name="form_key" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
<?php endif; ?>
<div class="qty-field">
<label for="qty"><?php echo $this->__('Qty:') ?></label>
<div class="qty-holder">
<input type="text" name="qty" id="qty_<?php echo $_product->getId(); ?>" maxlength="12" value="<?php echo $product->getProductDefaultQty() * 1 ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
<div class="qty-changer">
<i class="icon-up-dir"></i>
<i class="icon-down-dir"></i>
</div>
</div>
</div>
<?php if (!Mage::getStoreConfig("ajaxcart/addtocart/enablecategory", $code)) :?>
</form>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
If your changing in your core code then add the below code in your List.phtml
<?php $session = Mage::getSingleton('customer/session', array('name' => 'frontend')); ?>
<?php if($session->isLoggedIn()) { ?>
//Your Add to Cart Button Html
<?php } else { ?>
// Your Login to Add to Cart Html
<?php } ?>
Put the above code everywhere on your frontend where your products are displaying.