I can create the regular submit button in the form api but what if I want to do something like this
$form['required_text'] = array(
'#markup' => '<button name="submit" value="submit" type="submit" class="primary-submit submit" id="edit-submit">Submit - markup
<img src="/img/arrow.png">
</button>',
);
This does not send the form. What do I need to do or does it need to be an input field?
You might wahnt to use an image_button type instead. Also at the moment you're not really using the form API properly, you can just add markup to the form like you're doing but it doesn't register the element in the form and thus won't run submit/validate handlers. Something like this would work:
$form['required_text'] = array(
'#type' => 'image_button',
'#value' => 'submit',
'#src' => '/img/arrow.png'
);
With that element you'll get a an <input type="image" /> with the correct image loaded in to it's source.
Hope that helps
Related
i use TYPO3 7.6.10
i use indexed_search 7.6.0
when i submit form i go to the target page and i get the results.
The url of target page is:
search.html?tx_indexedsearch_pi2%5Baction%5D=search&tx_indexedsearch_pi2%5Bcontroller%5D=Search
i want to remove action and controller variable form url to get:
search.html
i can do that adding a configuration to real url like this:
'searchConfiguration' => array(
array(
'GETvar' => 'tx_indexedsearch_pi2[action]',
'valueMap' => array(),
'noMatch' => 'bypass'
),
array(
'GETvar' => 'tx_indexedsearch_pi2[controller]',
'valueMap' => array(),
'noMatch' => 'bypass'
)),'135' => 'searchConfiguration'
Now i get a nice url but the submitted data is not sent!
How can i resolve it?
Those parameters are required for the controller to be routed by the request. Without them the sWord will not become processed by the controller and you will not get any results.
Instead of bypassing them you can rewrite them to get something like /search/perform/results/ or you can configure your form to use method="POST" instead of "GET" and add those parameters above into hidden fields of the form and make sure the form attribute does not have the arguments as parameters in the action. Example form in the result:
<form method="POST" class="header-search-form hidden-xs hidden-sm" action="suche.html">
<input type="hidden" name="tx_indexedsearch_pi2[controller]" value="Search">
<input type="hidden" name="tx_indexedsearch_pi2[action]" value="search">
<div class="input-group">
<input type="text" class="search-query form-control" placeholder="Suchen" id="default-search-input" name="tx_indexedsearch_pi2[search][sword]">
<span class="input-group-btn">
<button class="btn" type="button">
<i class="fa fa-search" aria-hidden="true"></i>
</button>
</span>
</div>
</form>
I'm trying to add button input to the form element. I'd like the rendered code to be <input type="button" ..."> I tried setting attribs field like so:
$this->addElement('submit', 'cancel', array(
'ignore' => true,
'label' => 'Anuluj',
'attribs'=>array('class' => 'class_name', 'type' => 'button') )
);
but i still got <input type="submit" ..."> instead <input type="button" ...">
Setting class attribute works, but setting the type doesn't. Any Idea to get type="button"?
Use button as the first parameter instead, which will give you a <button> HTML element instead (functionally the same as <input type="button" ..>).
Please use the below code for button
$this->addElement('button', 'submitted');
$submitElement = $this->getElement('submitted');
$submitElement->setAttrib('class',"btn-primary btn");
$submitElement->setAttrib('value', 'submitted');
$submitElement->setLabel('SUBMIT');
The Html code is,
<button name="submitted" id="submitted" type="button" class="btn-primary btn">SUBMIT</button>
I've got a problem with zend decorators and can't figure out how to place an element in form where i want to have him.
I got a form where decorators are putting my data into a table, but i want to have my submit out of the table. For now i have something like that:
for ($i = 0; $i < $numRows; $i++) {
$select = new Zend_Form_Element_Select('article' . $i);
$select->setAttrib('style', 'margin-top:10px;width:200px;');
$select->addMultiOption('1', $this->translate->_('Zatwierdzony do druku'));
$select->addMultiOption('0', $this->translate->_('Niezatwierdzony do druku'));
$select->setValue($rows[$i]['reviewed']);
$select->setDecorators(
array(
'ViewHelper',
array(
array('data' => 'HtmlTag'),
array('tag' => 'td', 'class' => 'padding5 tdcenter')
),
array(
'AnyMarkup',
array(
'markup' => $this->_getMarkupForRow($i, $rows),
'placement' => 'PREPEND',
)
),
array(
array('row' => 'HtmlTag'),
array('tag' => 'tr', 'openOnly'=>true)
),
),
array('submit'),
false
);
$this->addElement($select);
}
$submit = new Zend_Form_Element_Submit('updatetoprint');
$submit->setAttrib('id', 'updatetoprint');
$submit->setLabel('Zapisz');
$submit->setDecorators(
array(
'ViewHelper',
array(
array('data' => 'HtmlTag')
),
array(
array('row' => 'HtmlTag'),
array('tag' => 'div', 'closeOnly'=>true,'style' => 'float:left;')
)
//here i dont know how to get my submit on the bottom under the table...?
),
array('submit')
);
$this->addElement($submit);
On site that looks like this:
And i'd like to have my submit on the bottom under the table... Please help me :)
I don't see where you are assigning your form to the view or if your form is a Zend_Form or not so I'm going to make some assumptions.
I'm going to assume you are using Zend_Form to build your form and I'm going to assume you are assigning your form to the view in the traditional manner inside a controller action $this->view->form = $form;
So with that being said, in your view script you have access to each individual element simply by <?php echo $this->form->elemenetName ?> where elementName is the name you have given your element in your case your submit button has the name 'updatetoprint'.
With this in mind if you need to create a table or any other layout you could simply create generic elements in your form and just add them as needed to any view script. Might prevent you from performing all those gymnastics with decorators.
For example view.phtml might look like:
<form action="<?php echo $this->form->getAction() ?>" method="<?php echo $this->form->getMethod() ?>">
<table>
<tr>
<th>Dodal</th>
<th>Tutyl</th>
<th>Status</th>
</tr>
<!--you should probably put the next 5 lines into a partial and use partialLoop($data)-->
<tr>
<td><?php echo $this->form->dodal ?></td>
<td><?php echo $this->form->tutyl ?></td>
<td><?php echo $this->form->status ?></td>
</tr>
</table>
<?php echo $this->form->updatetoprint ?>
</form>
Then just style with css.
To setup the form to use the viewscript just use:
$form->setDecorators(array(
'PrepareElements',
array('ViewScript', array('viewScript' => 'form.phtml')),
));
where form.phtml is your viewscript name
[Edit]
After further consideration I realized that diplaying form elements in this manner has one serious drawback. The form is never initialized...the form tags are never sent. This edit is to correct that issue.
Sorry it took so long
I'd suggest adding all your elements apart from the submit button to a display group. You then give the display group a HtmlTag decorator (with the tag set to table), which will wrap all your elements with a table, making your HTML valid and giving you the layout you want.
I'm seeing lots of <tr> and <td> tags, but no <table> tag. What I think you are looking for is markup roughly like this:
<table>
<tr><td>info</td><td>more info</td><td>select element</td></tr>
<tr><td>info</td><td>more info</td><td>select element</td></tr>
<tr><td>info</td><td>more info</td><td>select element</td></tr>
</table>
<div>
<input type="submit">
</div>
What seems to be missing from your code are any decorators that produce the <table> and </table> tags. So, on the first iteration of the loop, use the AnyMarkup decorator to prepend a <table> and your header row. On the last iteration, add a decorator that appends the </table> tag.
Then your submit button (which is added last) should sit right underneath.
Not my idea, but I need a set of radio buttons, where the last buttons value is a select box. Visual explanation:
o Opt 1
o Opt 2
o |___SelectBox|
What it would look like in HTML:
<input type="radio" name="radioSet">Opt1
</input>
<input type="radio" name="radioSet">Opt2
</input>
<input type="radio" name="radioSet"><!-- Opt 3 -->
<select>
<option value="a"> aaa</option>
<option value="b"> bbb</option>
</select>
</input>
What I've done in ZF so far:
$picker = new Zend_Form_Element_Select('selectBox', array(
'multiOptions' => array('a'=>'aaa', 'b' =>'bbb'),
'decorators' => array(
array('Label', array('escape'=>false))
)
));
$this->addElement(
'radio',
'radioSet',
array(
'multioptions' => array(
'x'=>'Opt1',
'y'=>'Opt2',
'z'=>$picker //'Dropdown picker'
),
'label' => 'My Title:',
'decorators' => array(
'ViewHelper',
'Errors',
array('Description', array('escape' => false)),
'Label',
array('HtmlTag', array('tag'=>'div')),
),
)
);
But this returns just the 3 radio buttons, as well as the labels "Opt1" and "Opt2", but nothing after the third radio button.
I WANT it to be like the HTML code shown above, but this ZF code does not return it. Anyone an idea how this can be accomplished?
Thanks!
unfortunately you probably going to have to write a decorator to replace the label tag with a select. Looking at the code for the Zend_Form_Element_Radio() it specifically adds the label tag to the radio.
Thanks for your advices. I'm quite new to Zend, so I checked up how to make a custom view helper decorator, I couldn't manage to get it to work like that, but it helped me in another problem though.
I came to the solution, that it's easier to just add the select box as an individual element afterwards, and style it to the desired position with css.
Thanks again.
I want to add a specific class to an input if an error is genereted by the input.
For example, if input is empty and has required validator it shouls look like this:
<dd id="login-element">
<input type="text" name="login" id="login" value="" class="input-text error" />
<ul class="errors">
<li>Value is required and can't be empty</li>
</ul>
</dd>
class="input-text error"
Please tell me how to do that.
I solved it with jquery! :)
I used the standard Decorators and manipulate the class of the preview Object in DOM.
$('ul.errors').prev().addClass("FieldError");
Have a look at this tutorial to get a better understanding where to change your code: http://devzone.zend.com/article/3450-Decorators-with-Zend_Form
In your case, I would recommend either replacing the ViewHelper decorator with a decorator that creates the output you want. You can extend the Zend_Form_Decorator_ViewHelper class for this with your own code and overwrite the getElementAttribs() method to insert your class attribute.
Rather than creating a Decorator, easy way to do this is set the class while you add the element in the form class. For example, you can use the following in the init() method of your Zend_Form class
$this->addElement('text', 'email', array(
'label' => 'Your email address:',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(
'EmailAddress',
),
'class' => 'input-large'
));