I have a content type with a number of Field Collection fields.
The design for this form is relatively complex and cannot simply be styled with CSS. I want to output the form in a template, so each individual field can be styled.
I spent 6 hours last night looking for a solution to this. I've seen custom modules, hook_form_alter and various methods that might use Display Suite or other modules. None have worked for me so far.
My goal is to simply output the form fields (including Field Collection fields) in a template for styling. Has anybody achieved this?
You might be able to do it by creating an override template for the node add/edit page.
You will first need to add a new template suggestion for node forms. The first section of this page shows you how to do this:
https://www.drupal.org/node/1092122
After that, you should be able to print individual form elements into the new template. For example:
<div class="column-left">
<?php print drupal_render($form['first_name']); ?>
<?php print drupal_render($form['last_name']); ?>
</div>
<div class="column-right">
<?php print drupal_render($form['email']); ?>
<?php print drupal_render($form['phone']); ?>
</div>
Related
In a Yii application, I'm working on, there is a simple CActiveForm, where all elements are model related and look like this:
<div class="row">
<?php echo $form->labelEx($model, 'foo'); ?>
<?php echo $form->textField($model, 'foo', array(/* HTML options */)); ?>
<?php echo $form->error($model, 'foo'); ?>
</div>
Now I want to implement following case:
The should be a radio button element bar with two options. Depending on the selected option different form elements should be displayed (a dropdown list with existing bar-entries oder a set of field to create a new one). In the controller I want to analyze the field bar and, if needed (means e.g. if bar == 1) use the provided field set to create a new table entry.
CActiveForm#radioButton(...) needs a model as input. But for this case the model is not relevant -- the radio button I need should only contain/provide the information, how the data has to be processed. Is there a Yii conform way to implement this requirement and create a "non-model" form element for a Yii CActiveForm?
Hello SilverStripe Community,
Forgive me if this is an elementary question, but in a custom form template, how can I output individual action fields without looping through all of them? Is there a way of doing that?
For example, when it comes to the form fields, I can loop through them with this:
<% loop $Fields %>
$Field
<% end_loop %>
OR I can output individual form fields like this:
$Fields.dataFieldByName(Email)
Is there something similar for form actions?
I know I can loop through them with:
<% loop $Actions %>
$Field
<% end_loop %>
but as I have one huge client form with several action buttons located in various positions in the form, I need to be able to output the action buttons individually with a great degree of control.
The only way I know how to achieve this at the moment is to manually create the markup for each action throughout the form, like this:
<button id="{$FormName}_action_doLogin" class="action button-login" value="Login" name="action_doLogin" type="submit">
<span>Login</span>
</button>
...but I'm looking for something like:
$Actions.dataFieldByName(Login)
OR
$Actions.Field(Login)
$Actions.Field(AddressLookup)
etc.
Does something like that exist in SilverStripe templating for Actions?
Thanks in advance.
all actions are prefixed with "action_"
so function
$Actions.dataFieldByName(Login)
works, but you need to call it as :
$Actions.dataFieldByName(action_Login)
I used zf2 to design a website.
And the form is something like this:
$this->add(array
'options'=>array(
'label'=> 'title1'))
And finally it shows like this:
<form>
<fieldset>
<legend>title1</legend>
<label>****</label>
</fielset>
</form>
Now, I wanna add a link or an image after the title1, for example:
<form>
<fieldset>
<legend>title1<a href=''>link</a></legend>
<label>****</label>
</fielset>
</form>
How can I do this?
You can't. Well, at least not without overwriting the specific ViewHelper (probably formCollection()). In ZF2 all Labels are run through the Zend\View\Helper\EscapeHtml ViewHelper. Therefore using any sort of HTML inside Labels is not supported in any way.
While going by specification it may be allowed to use inline-elements inside the <legend> Element, semantically it looks a little different. The <legend> shall do nothing but to describe the contents of the <fieldset>.
Anyways, opinions aside, as i've mentioned, you'll have to overwrite the ViewHelper and then skip the use of the EscapeHtml ViewHelper, as it's done in this line of the formCollection() Code
I've been creating with a ajax and doctrine chain-dropdown to select a category. I put them in component. It works like this:
http://www.plus2net.com/php_tutorial/ajax_drop_down_list.php
Im trying to replace default category dropdown build on schema and related with current table. When in
/lib/form/doctrine/TabbleForm.class.php
I remove a field with code:
unset($this['category']);
And in the tamplate which has a form body I paste a component code (with this dynamic ajax-based dropdown):
include_component('add', 'selectcategory',array('catid' => 0));
I have notice:
Unexpected extra form field named "category".
How can I replace that default code with category-field code from component / module?
How do you display your form in the template? Using a basic <?php echo $form; ?> or manually like:
<?php echo $form['field']->renderLabel() ?>
<?php echo $form['field']->render() ?>
<?php echo $form['field']->renderError() ?>
I suggest you to use the second method, at least using <?php echo $form['field']->renderRow() ?>. This way, you won't have to unset the categoy field from your Form class. But you will have to name the select tag in your component the same way the form do.
If the form display:
<select id="formname_category" name="formname[category]">...</select>
You will have to use the same name (for the second select I guess). Then, you won't have any problem in your form and, more important, the validator related to your category field will also work!
I got few issues proting a pear based form to zend form.
I have few elements I need :
Basic Elements
Groups
Group Elements
Sections
I previously used templates to render the forms on Pear. I obviously cannot use pre-existing zend decorators, since I need to specify css classes for each of the components of my base elements.
To see the issue I need to render this, which is the template for a basic element :
<li class = "{position_in_the_form} {error}">
<label class="{label_class}"> {label}
[<span class="required_class"> * </span>]
</label>
<div> {element_content} </div>
[<p class = "{error_class}"> {error_message} </p>]
</li>
So as you can see I have many dynamic things I would like to be able to specify : position in the form, class for the label, class for the required section, the class for the error.
I would also like to be able to specify this from an ini file. I manage to set up the basic meta from the ini but not custom fields.
One of the reason I cannot use basic decorators is that I need to have "error" in the "li" class when there is an error in the element or the sub_form.I'm not sure this is possible with the error decorator... (correct me if I'm wrong)
Also, for the group I need something handling the errors, and since the core groups don't handle errors I need to subclass the sub_form. But how can I create a subform in an ini file and I don't know how to provide parameters to the sub form fromn the ini.
The main idea here is to be able to have visual and logic groups of elements in a form. For example I need a 'name' group with fullname, middle name, etc. This also implies a global validator for this "name" group.
An other thing is that I want to be able to position these groups : left half, right half, full
I got the css ready for this and working with pear.
So what I need is a simple solution, with few code and ini configurations. Unfortunately I think I got stuck in something too complicated, so if someone has any idea about a simple architecture it would be amazing!
Thanks in advance for your help,
Best, Boris
In your complex decoration need, you might want to use the ViewScript Zend_Form_Element_Decorator
$element->setDecorators(array(
array('ViewScript', array('viewScript' => 'path/to/your/views/element.phtml')),
));
and then in path/to/your/views/element.phtml, more or less something like
<li class="<?php echo $this->element->getAttrib('position_in_the_form') ?> <?php echo $this->element->hasErrors() ? 'error' : '' ?>">
<label class="<?php echo $this->element->getAttrib('label_class') ?>">
<?php echo $this->formLabel($this->element->getName(),
$this->element->getLabel()) ?>
<? if ( $this->element->isRequired() ) { ?>
[<span class="required_class"> * </span>]
<? } ?>
</label>
<div> <?php echo $this->{$this->element->helper}(
$this->element->getName(),
$this->element->getValue(),
$this->element->getAttribs()
) ?> </div>
<? if ( $this->element->hasErrors() ) { ?>
[<p class="<?php echo $this->element->getAttrib('error_class') ?>"> <?php echo $this->formErrors($this->element->getMessages()) ?> </p>]
<? } ?>
</li>
This is only a drafty snippet of code, but should lead you in the direction you aim.
Regards