ZF2 form formatting? - php

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>

Related

dropBox is not visible in the form - CakePHP-AjaxMultiUpload

I am using the CakePHP-AjaxMultiUpload Plugin, and have following code inside edit.ctp but the drop box is not visible here.
<div class="useTypes form">
<?php echo $this->Form->create('UseType'); ?>
<fieldset>
<legend><?php echo __('Edit Use Type'); ?></legend>
<?php
echo $this->Form->input('id');
echo $this->Form->input('name');
echo $this->Form->input('description');
echo $this->Upload->edit('UseType', $this->Form->fields['UseType.id']);
?>
</fieldset>
<?php
echo $this->Form->end(__('Submit')); ?>
</div>
but when I use the following code alone , it is visible
<?php echo $this->Upload->edit('UseType', $this->Form->fields['UseType.id']);?>
I tried this in cakephp 2.6 with default theme.
You are not supposed to wrap $this->Upload->edit() inside a <form> tag, as it already creates its own form.
You might also need to replace:
$this->Form->fields['UseType.id']
with:
$this->Form->value('UseType.id')
In summary, this should work:
<?php echo $this->Form->create('UseType'); ?>
<fieldset>
<legend><?php echo __('Edit Use Type'); ?></legend>
<?php
echo $this->Form->input('id');
echo $this->Form->input('name');
echo $this->Form->input('description');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
<?php echo $this->Upload->edit('UseType', $this->Form->value('UseType.id'));?>
Edit
If you need to upload files on your /use_types/add view, you can do the following.
In UseTypeController::add() include:
$this->set('id',CakeText::uuid()); //String::uuid() for CakePHP 2.6 or lower
and in /app/View/UseTypes/add.ctp:
<?php echo $this->Form->input('id',array('type' => 'hidden', 'value' => $id)); ?>
The drawback is that if you fail to save your model after uploading files via AJAX, these will be left orphaned.

Add tabs and fields to custom joomla component

How can i add more tabs and fields to a joomla component in backend,
-Tried editing the view xml file adding more fieldsets, no success
-Tried editing the edit file in view admin component, no success,
In other words i want to achieve this, just like the image
Any help?
You have to set it to the view template admin\views\*view_name\tmpl\*template_name.php.
The structure that you have to use is:
<?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'general')); ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'general', JText::_('COM_COMPONENT_NAME_TAB_1_NAME', true)); ?>
...
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'advanced', JText::_('COM_COMPONENT_NAME_TAB_2_NAME', true)); ?>
...
<?php echo JHtml::_('bootstrap.endTab'); ?>
<?php echo JHtml::_('bootstrap.endTabSet'); ?>
You could also check core components to get more examples.
As for the contents of each tab, you could restrict the loop to get the fields of one fieldset only using:
<?php foreach ($this->form->getFieldset("general") as $field): ?>
<div class="control-group">
<div class="control-label"><?php echo $field->label; ?></div>
<div class="controls"><?php echo $field->input; ?></div>
</div>
<?php endforeach; ?>

How Can I Add Value to Save / Apply Changes with JToolBarHelper

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>

I want to get value from fields loop .How can I do?

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

How to use checkbox with wpalchemy

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.

Categories