I have an edit view which need to pass a hidden value through the form in a Joomla 2.5 component. Where would I go about adding this form value?
Here is my attempt (that is not working):
In the ../admin/models/forms/componentview.xml file I have added the following field:
<field
name="variableToPassBackToMainView"
type="hidden"
value="1"
/>
My thought was that by adding this hidden field to the model form, when it was saved then the variableToPassBackToMainView would be picked up by the new view. The view has the following variable definition to retrieve the value:
$variableToPassBackToMainView = $_REQUEST["variableToPassBackToMainView"];
Updated Info:
Joomla 2.5 Component
Here is the edit.php
<?php
defined('_JEXEC') or die('Restricted access');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
$params = $this->form->getFieldsets('params');
?>
<form action="<?php echo JRoute::_('index.php?option=com_mycomponent&layout=edit&id='.(int) $this->item->id); ?>" method="post" name="adminForm" id="mycomponent-form" class="form-validate">
<div class="width-60 fltlft">
<fieldset class="adminform">
<legend><?php echo JText::_( 'COM_MYCOMPONENT_DETAILS' ); ?></legend>
<ul class="adminformlist">
<?php foreach($this->form->getFieldset('componenttitledetails') as $field): ?>
<li><?php echo $field->label;echo $field->input;?></li>
<?php endforeach; ?>
</ul>
</div>
<div class="width-40 fltrt">
<?php echo JHtml::_('sliders.start', 'mycomponent-slider'); ?>
<?php foreach ($params as $name => $fieldset): ?>
<?php echo JHtml::_('sliders.panel', JText::_($fieldset->label), $name.'-params');?>
<?php if (isset($fieldset->description) && trim($fieldset->description)): ?>
<p class="tip"><?php echo $this->escape(JText::_($fieldset->description));?></p>
<?php endif;?>
<fieldset class="panelform" >
<ul class="adminformlist">
<?php foreach ($this->form->getFieldset($name) as $field) : ?>
<li><?php echo $field->label; ?><?php echo $field->input; ?></li>
<?php endforeach; ?>
</ul>
</fieldset>
<?php endforeach; ?>
<?php echo JHtml::_('sliders.end'); ?>
</div>
<div>
<input type="hidden" name="task" value="componentview.edit" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
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 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.
I'm using joomla and I have begun to develop a web app, I want to get values from form fields. Normally I use $_POST but this page didn't work.
This is my default.php >>>
<?php
defined('_JEXEC') or die;
JHtml::_('behavior.keepalive');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
?>
<div class="item" <?php echo $this->pageclass_sfx?>">
<?php if ($this->params->get('show_page_heading')) : ?>
<h1><?php echo $this->escape($this->params->get('page_heading')); ?></h1>
<?php endif; ?>
<form id="add-item" action="<?php echo JRoute::_('index.php?option=com_stationery&task=item.save'); ?>" method="post" class="form-validate" enctype="multipart/form-data">
<?php foreach ($this->form->getFieldsets() as $fieldset): // Iterate through the form fieldsets and display each one.?>
<?php $fields = $this->form->getFieldset($fieldset->name);?>
<?php if (count($fields)):?>
<fieldset>
<?php if (isset($fieldset->label)):// If the fieldset has a label set, display it as the legend.
?>
<legend><?php echo JText::_($fieldset->label);?></legend>
<?php endif;?>
<dl>
<?php foreach($fields as $field):// Iterate through the fields in the set and display them.?>
<?php if ($field->hidden):// If the field is hidden, just display the input.?>
<?php echo $field->input;?>
<?php else:?>
<dt>
<?php echo $field->label; // Show label for registor ?>
<?php if (!$field->required && $field->type!='Spacer'): ?>
<?php endif; ?>
</dt>
<dd><?php echo ($field->type!='Spacer') ? $field->input : " "; ?></dd>
<?php endif;?>
<?php endforeach;?>
</dl>
</fieldset>
<?php endif;?>
<?php endforeach;?>
<div>
<button name="save" type="submit" class="btn btn-success" class="validate"><?php echo JText::_('Save');?></button>
<?php echo JText::_('or');?>
<a class="btn btn-danger" href="<?php echo JRoute::_('/stationery/index.php/add-items');?>" title="<?php echo JText::_('JCANCEL');?>"><?php echo JText::_('JCANCEL');?></a>
<input type="hidden" name="option" value="com_stationery" />
<input type="hidden" name="task" value="item.save" />
<?php echo JHtml::_('form.token');?>
</div>
</form>
<script>
This is loop from field.xml to show each field. I want to get value in that inputbox. now I can get to javascript variable but I can't use to save in my table. I want php variable ($....). How can I get it? Please help me. Thank you
In Joomla 2.5+ you could use JRequest, but since it's deprecated you should:
JFactory::getApplication()->input->get...
however looking at your code there may be a simpler approach just bind the input to the table model
I am using ZF2 and have a form which defines a bunch of elements, and then I render it in my phtml like this:
<?php
$form = $this->form;
$form->prepare();
echo $this->form()->openTag($form);
echo $this->formlabel($form->get('description'));
echo $this->formRow($form->get('radioButton'));
echo $this->form()->closeTag();
?>
Which draws a label and a radio button.
My question is how can I then format these elements to my liking? For example make the radio buttons displayed horizontally rather than vertically and maybe change the location of the label.
There's nothing stopping you from formatting them as you have there, you could put the elements inside a list, or andd any additional markup you want to style as you wish.
<?php
$form = $this->form;
$form->prepare();
echo $this->form()->openTag($form);
?>
<ul class="form-list">
<li>
<div class="form-control">
<?php echo $this->formlabel($form->get('description')); ?>
<?php echo $this->formElementErrors($form->get('description')) ?>
<?php echo $this->formElement($form->get('description')); ?>
</div>
<div class="form-control">
<?php echo $this->formlabel($form->get('radioButton')); ?>
<?php echo $this->formElementErrors($form->get('radioButton')) ?>
<?php echo $this->formElement($form->get('radioButton')); ?>
</div>
</li>
</ul>
<?php echo $this->form()->closeTag() ?>
If you wanted to have control over the actual elements/inputs themselves you could do something like this:
<label>
<?php echo $form->get('radioButton')->getLabel() ?>
<input class="bob" type="radio"
name="<?php echo $form->get('radioButton')->getName() ?>"
value="<?php echo $form->get('radioButton')->getValue() ?>"
/>
</label>
I have used following code to create a checkbox in WordPress pages (in admin section):
<?php while($mb->have_fields_and_multi('sidebar-block')): ?>
<?php $mb->the_group_open(); ?>
<!-- Some more code here for other fields -->
<p class="checkbox">
<input name="<?php $metabox->the_name('blue-block'); ?>" type="checkbox" value="1" <?php if ($metabox->get_the_value('blue-block')) echo ' checked="checked"'; ?>>
<label>Do not use Blue Block for content</label>
</p>
<?php $mb->the_group_close(); ?>
<?php endwhile; ?>
Above code is working fine. My question is how can i check if this checkbox is checked on the main website (frontend)?
Following is the code in my template for frontend:
<?php
$my_meta = get_post_meta($post->ID,'_sidebar_meta',TRUE);
if ($my_meta['sidebar-block']) {
foreach ($my_meta['sidebar-block'] as $sidebar)
{
?>
<div id="aside-blue">
<?php if ($sidebar['side_heading']) { ?>
<h2 class="sideheading"><?php echo $sidebar['side_heading']; ?></h2>
<?php } ?>
<?php echo apply_filters( 'the_content', $sidebar['side_content'] ); ?>
</div>
<?php } ?>
<?php } ?>
I want to add id="aside-blue" only when checkbox is checked.
i tried following code for this, but it's not working
<?php
$my_meta = get_post_meta($post->ID,'_sidebar_meta',TRUE);
if ($my_meta['sidebar-block']) {
foreach ($my_meta['sidebar-block'] as $sidebar)
{
?>
<div <?php if ($sidebar['blue-block'] == 'yes') { ?>id="aside-blue"<?php } ?>>
</div>
<?php } ?>
<?php } ?>
Check in the wp_postmeta table how the value is stored. When I used checkboxes, the values were serialized. You'll probably need to unserialize it before using the meta value.