How to Spread formwidgets in doctrine into multiple columns? - forms

I'm using symfony1.4 with doctrine. I'm able to insert/update/delete records using form widgets. But the problem is i have some 75 fields in a single form which i want to spread into two columns.Please tell me a way to implement this please.....

This can be done by rendering each one individually on your template or view... For example, if your form has a widget called name, in your template of partial, you can render it by doing:
//this will render the row as the assigned formater does
<?php echo $form['name']->renderRow()?>
or
//in a table
<tr>
<td>
<!-- will output only the label -->
<?php echo $form['name']->renderLabel()?>
</td>
<td>
<!-- will output only the 'input' -->
<?php echo $form['name']->render()?>
<!-- will output only the error messages -->
<?php echo $form['name']->renderError()?>
</td>
</tr>
If you have any doubt check the Symfony's Forms for Web Designers for more details.

Related

MailChimp custom template problems with drag and drop blocks

I am creating a custom MailChimp template but having issues when using the mc:repeatable element. I have it on a wrapped around a block of code and in the editor when creating a campaign, it works fine, I can spawn a new version of the parent block and move it around in the template, but when I preview, or send the email, the child block that was spawned from the parent sits below it's parent and not where I have placed it following spawning it from the parent block... Something seems to be wrong? (Heavily simplified) Code example below... Anyone any ideas on the fix???
<!-- BLOCK A -->
<div style="width:100%" mc:repeatable="CONTENTBLOCK_A">
<p>This is block A</p>
</div>
<!-- end of BLOCK A -->
<!-- BLOCK B -->
<div style="width:100%" mc:repeatable="CONTENTBLOCK_B">
<p>This is block B</p>
</div>
<!-- end of BLOCK B -->
So, when creating a new campaign, if I duplicate BLOCK A and position the duplicated BLOCK A below BLOCK B - in the preview within the campaign editor it looks fine, but when I click to view it into PREVIEW MODE, or send a PREVIEW EMAIL - the duplicated BLOCK A sits above BLOCK B and below its original spawned parent BLOCK A element...
Any ideas? Are the HTML COMMENTS (e.g. < !-- --> ) The issue perhaps?
Very late, but I was able to find success using this:
<table mc:repeatable="content" mc:variant="variant_1">
<tr>
<td mc:edit="section_1">
Variant 1 Content
</td>
</tr>
</table>
<table mc:repeatable="content" mc:variant="variant_2">
<tr>
<td mc:edit="section_2">
Variant 2 Content
</td>
</tr>
</table>
<table mc:repeatable="content" mc:variant="variant_3">
<tr>
<td mc:edit="section_3">
Variant 3 Content
</td>
</tr>
</table>
More in depth explanation can be found here: Create Editable Content Areas with MailChimp’s Template Language

form submission not always working

I'm trying to figure out the problem here and I can't see why its not working. I've got an edit form that 99% of the time submits fine but for some records it doesn't. This is some of the code on the form:
<?php echo form_open('administration/categories/edit_offer_content_success')?>
<table cellpadding="6" cellspacing="0" class="admin-panel table_style">
<tr>
<th><b>Edit Offer</b><?php echo form_hidden('id',$offer->id)?></th>
</tr>
<tr>
<td>Name:<br /><?php echo form_input(array('name' => 'name', 'value' => $offer->name, 'size' => '100'))?></td>
</tr>
<tr>
<td align="center" valign="middle" height="20"><?php echo form_submit('','Save')?></td>
</tr>
</table>
<?php echo form_close()?>
When you click on the save button it should go to the edit_offer_contents function but on some records, it goes to the index page of the site instead. I remmed out all the code in this function and set it to load a debug page instead hoping to track down where the error was occurring, but on the records that won't save, it still goes to the index page of the site so it looks like its not getting to the function but I can't see why. There is no validation as far as I can see and I'm now banging my head against the wall
function edit_offer_content_success()
{
$this->output->enable_profiler(TRUE);
$this->load->view('admin/debug');
// redirect ('administration/categories/edit_offer/'.$id,'refresh');
}
if anyone has any ideas I'd be very grateful
i suppose you have one of the columns set as unique key in the database and sometimes trying to update the values of those columns to some existing values.

How can I dynamically create multiple checkboxes with Zend Form?

Could you please help me to solve my problem?
I would like to place a checkbox on every row of a list of users built with database information and add a validation button to post my form. My list should look something like this:-
So the user will select the checkbox linked to the student he wants to validate.
The number of rows of the result is variable, so i don't know how to do it.
I hope i've been clear in my description.
You haven't shown any code, but I am assuming that you get the number of students somewhere in your controller.
To achieve what you want with Zend_Form, you will need to render each element individually, but first you need to find a way of adding the correct number of elements to your form.
Preferably, you would do this in your form class to keep the logic out of the controller, but to keep this answer simple I will show you how to achieve this in your controller, you can then adapt the code as you wish.
$numStudents = getNumberOfStudentsSomehow();
$studentForm = new yourFormClass();
for($i = 0; $i <= $numStudents; $i++){
$checkBoxes[] = new Zend_Form_Element_Checkbox('checkBox_' . $i);
}
$studentForm->addElements($checkBoxes);
$this->view->studentForm = $studentForm;
Your form now has the correct number of check boxes in it and you can pass it to the view.
In the view you have several options for rendering the form, either a view partial as suggested by RockyFord, a view helper (documentation here), create a custom view script for your form, or render directly in your view.
To get you started you can render individual elements from your form in your view like this:-
echo $this->view->studentForm->checkBox_0;
I think this might be a situation were a partialLoop() might be the best solution.
in your controller get your data from the model as usual and assign it the data to the view
$this->view->modelData= $data;
next make a new .phtml file in /views/scripts for this demo we'll call it _demoRow.phtml then code the html and php for one table row (in this case).
<tr>
<td><?php echo $this->name ?></td>
<td><?php echo $this->class ?></td>
<td><?php echo $this->birth_date ?></td>
<td><input type="checkbox" name="id" value="<?php echo $this->id ?> /></td>
</tr>
Then in your normal view just put the static information and render the partial
<form action="/your/action/url" method="post">
<table class="spreadsheet" cellspacing="0">
<tr>
<th>Student Name</th>
<th>Class</th>
<th>Birth Date</th>
<th>Select</th>
</tr>
<?php echo $this->partialLoop('_demoRow.phtml', $this->modelData) ?>
<tr>
<input type="submit" name="submit" value="valider" />
</tr>
</table>
</form>
This should approximate what you're looking.

Zend Framework: what is the difference between partials and placeholders

In Zend Framework, Can anybody explain the difference between partial and placeholder?
From my understanding, one can render a particular template / container by using both placeholders and partials.
In which condition should one use a partial and what scenario is optimal use for placeholders?
It's pretty simple, the placholder is used to persist data between views and layouts and partials are used in specific views to do specific tasks.
See these excerpts from the reference.
77.4.1.6. Placeholder Helper: The Placeholder view helper is used to persist content between view scripts and view instances. It also
offers some useful features such as aggregating content, capturing
view script content for later use, and adding pre- and post-text to
content (and custom separators for aggregated content).
77.4.1.5. Partial Helper: The Partial view helper is used to render a specified template within its own variable scope. The primary use is
for reusable template fragments with which you do not need to worry
about variable name clashes. Additionally, they allow you to specify
partial view scripts from specific modules.
Here is a simple example of a placeholder, that sounds like what you want. (to persist data)
<?php
//this is placed in my layout above the html and uses an action helper
//so that a specific action is called, you could also use view helpers or partials
$this->layout()->nav = $this->action('render', 'menu', null,
array('menu' => $this->mainMenuId))
?>
<div id="nav">
//Here the placeholder is called in the layout
<?php echo $this->layout()->nav ?>
</div>
in this case the menu id's are setup in the bootstrap, however this is not requiered it just simple.
protected function _initMenus() {
$view = $this->getResource('view');
$view->mainMenuId = 4;
$view->adminMenuId = 5;
}
[EDIT]
I think a better placeholder example might be in order. This place holder is a small search form I use in several actions in several controllers in different configurations.
In this configuration this form is setup to search just for music artists, the controllers that use this placeholder will have different paths for setAction(), different Labels and sometimes different placeholder text. I use this same form to search music and video databases.
I you always use the same setup or have more interest in doing it then I do, this can be setup as a plugin.
//in the controller
public function preDispatch() {
//add form
$searchForm = new Application_Form_Search();
$searchForm->setAction('/admin/music/update');
$searchForm->query->setAttribs(array('placeholder' => 'Search for Artist',
'size' => 27,
));
$searchForm->search->setLabel('Find an Artist\'s work.');
$searchForm->setDecorators(array(
array('ViewScript', array(
'viewScript' => '_searchForm.phtml'
))
));
//assign form to placeholder
$this->_helper->layout()->search = $searchForm;
}
I use the placeholder in my layout (can also be used in any view script). The search form is rendered when the placeholder has a value and not rendered when the placeholder has no value.
//in the layout.phtml
<?php echo $this->layout()->search ?>
and just to be complete, here is the partial that the form uses as a viewscript decorator.
<article class="search">
<form action="<?php echo $this->element->getAction() ?>"
method="<?php echo $this->element->getMethod() ?>">
<table>
<tr>
<th><?php echo $this->element->query->renderLabel() ?></th>
</tr>
<tr>
<td><?php echo $this->element->query->renderViewHelper() ?></td>
</tr>
<tr>
<td><?php echo $this->element->search ?></td>
</tr>
</table>
</form>
</article>
This example should really illustrate the difference between partial and placeholder.
I think what might be more helpful for you here is either a custom view helper, possibly expanding on the existing Zend_View_Helper_FormSelect class or create a custom Zend Form element that suits your needs. Alternatively, a helper script that's in a general location may be the best bet.

Html coders + zend form

So I use a zend framework, but for all commercial projects I am not using zend form component.
HTML+Js coders are working on frontend and I don't want to have nothing with it, I just connect the final view in my zf based application.
So for example I have in view a html form which looks like this:
http://pastie.org/1668143
So form design, elements and classes can be changed by frontend coders, and I want to know is there easy way for me, to use zend form with this concept (in each project form code looks different of course )?
My main problem here is code duplication in my controllers, which in this case looks something like this:
http://pastie.org/1668023 (please don't take exceptions and loggedMember seriously, they are just used for this snippet, to demonstrate a problem, which I have)
So, what would be the best solution for problem which I have, what do u think :) ?
If you have absolutely no control over the form's html structure, but still want to maximize the use of Zend_Form's features, use Zend_Form_Decorator_ViewScript.
http://framework.zend.com/manual/en/zend.form.standardDecorators.html (last section)
$element->setDecorators(array(array('ViewScript', array(
'viewScript' => '_element.phtml',
'class' => 'form element'
))));
I would do it like this:
create a form class that has all elements, validators and filters
create an instance of the form in your action and set the view script(s) (this way you can change them per controller and still have very little duplicated definition code.
Splendid, I don't understand why you would have a problem with code duplication, in your 2nd link, you are performing your checks, then check if the page is a post request, then performing the checks again, yes its duplicated, but I don't understand what you are trying to explain by doing this?
As for the form, its up to you how you use it, you could create the form object, then instead of ever out putting the form, simply pass it the data from your designers form, and use it to validate things.
Or you could use custom templates for the form, OK it means you don't give the designers quite as much freedom of them designing a form and you sorting the results, but they can still do their best at it.
This is the setup I use, after all I am in charge of the functionality as the programmer, the designers just make it look good what the user see's.
So for example, if I want to create an input element I can:
$arrival_time = $this->createElement('text', 'arrival_time', array(
'required' => true,
'label' => 'Arrival Time:',
));
$arrival_time->removeDecorator('HtmlTag');
$this->addElement($arrival_time);
Notice I have removed the HtmlTag decorators here - I don't need them for the markup as the designers will be arranging things for me.
Next thing to do is tell the form to use the layout the designers have made:
$this->setDecorators(array(array('ViewScript', array('viewScript' => 'NewArrivalsForm.phtml'))));
Here my template is within the view's, script's directory.
Now the designers have a few options. They could do:
<table border="0" width="100%">
<tr>
<td>
<?php echo $this->element->arrival_time; ?>
</td>
This will give you the following output:
<td>
<dt id="arrival_time"><label for="arrival_time" class="required">Arrival Time:</label></dt>
<input type="text" name="arrival_time" id="arrival_time" value="" />
</td>
If there we're an error, that would be presented as well. You could remove the decorators 'Label', 'Description' & 'Errors' as well, to make it simply an input box:
<td>
<input type="text" name="arrival_time" id="arrival_time" value="" />
</td>
Even once you have removed the decorators, the designers could still use for example:
<tr>
<td>
<?php echo $this->element->time_on_site->getLabel(); ?>
</td>
</tr>
<tr>
<td>
<?php echo $this->element->time_on_site ?>
</td>
This will allow them to lay the form out exactly as they want to. But it will still allow you to use the full power of Zend_Form for your final validation checks. Take a look inside the Zend/form/element.php for all the methods you and your designers can use on the form element.