How to convert below html text field into zend form,
<div class="control-group">
<label class="control-label">IP</label>
<div class="controls">
<input placeholder="" data-mask="999.999.999.999" class="text login_input" type="text">
<span class="help-inline">192.168.110.310</span>
</div>
I use zend 1.2 ,my challenge is data-mask="999.999.999.999"how to add a zend form,
I give below code, but not working,
$ipRange = new Zend_Form_Element_Text('ipRange');
$ipRange->class = "text login_input";
$ipRange->data-mask = "999.999.999.999";
$ipRange->addValidator('Ip', array('allowipv6' => false));
$ipRange->setDecorators(array('ViewHelper','Description'));
$ipRange->setAttrib('required', 'required');
$ipRange->setRequired(true);
$this->addElement($ipRange);
Try this:
$ipRange->setAttrib('data-mask', '999.999.999.999');
Related
I want to insert with form TextArea input HTML with ASP code to Access 2000 database.
This is OK, but when retrieve the recordset from an ASP page, the part of ASP code is just text. What I'm doing wrong?
What I have tried:
The Insert Code:
<%
Set MM_editCmd = Server.CreateObject ("ADODB.Command")
MM_editCmd.ActiveConnection = MM_conn_STRING
MM_editCmd.CommandText = "INSERT INTO KioskLayout (KioskHtml) VALUES (?)"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 203, 1, 536870910, Request.Form("KioskLayHtml")) ' adLongVarWChar
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
%>
The HTML Form Code:
<form METHOD="POST" name="Layout" action="<%=MM_editAction%>" class="center">
<textarea class="form-control" id="KioskLayHtml" name="KioskLayHtml">
<!--This is The TextArea field Input -->
<div class="grid-container">
<div class="main"><%=rs("today")%></div>
<div class="Left"><%=rs("tomorrow")%></div>
<div class="Bottom"><%=rs("yesterday")%></div>
</div>
<!--End Of TextArea field Input -->
</textarea>
<input type="hidden" name="MM_insert" value="Layout">
<input type="submit" name="button" id="button" value="Submit">
</form>
But when retrieve the recordset from an ASP page shows this as text.
<%=rs("today")%>
<%=rs("tomorrow")%>
<%=rs("yesterday")%>
and view the page source shows this:
<div class="grid-container">
<div class="main"><%=rs("today")%></div>
<div class="Left"><%=rs("tomorrow")%></div>
<div class="Bottom"><%=rs("yesterday")%></div>
</div>
Any help?
IS the file saved as .ASP ? It appears to be pure HTML in which case what's between brackets won't be parsed on the server.
We build a custom bundle follow with this instructor https://blog.sulu.io/how-to-develop-a-bundle-in-the-sulu-admin-1
We need to know how to pass data from a database to render radio input choices or dropdown select.
We try to create an add/edit form and in the form, we have a radio and dropdown we made with hardcore in HTML file in Vendor/TransportationBundle/Resources/public/js/components/transportation/form/form.html
The code is
<div class="grid-row">
<label for="transportation-transportationType"><%= translations.transportationType %></label>
<div class="custom-radio">
<input name="transportationType" id="transportation-transportationType-1" type="radio"
class="form-element content-type" value="1" data-mapper-property="transportationType">
<span class="icon"></span>
</div>
<span class="clickable"><%= translations.private_shuttle %></span>
<div class="custom-radio">
<input name="transportationType" id="transportation-transportationType-2" type="radio"
class="form-element content-type" value="2" data-mapper-property="transportationType">
<span class="icon"></span>
</div>
<span class="clickable"><%= translations.shared_shuttle %></span>
<div class="custom-radio">
<input name="transportationType" id="transportation-transportationType-3" type="radio"
class="form-element content-type" value="3" data-mapper-property="transportationType">
<span class="icon"></span>
</div>
<span class="clickable"><%= translations.airplane %></span>
</div>
Is this have a way to change those radio to fetch the data from an array or a way to fetch the data from some controller action? or Have another way to use twig file with twig feature instead of html file?
Please provide a solution for us? Thank you
Sorry for my English.
You can e.g. check this Controller from the core. You can get data from wherever you want in the controller and pass it to the template:
<?php
class AcmeController {
public function testAction() {
$data = /* Get data somehow */;
return $this->render('template', ['data' => $data]);
}
}
Then you can access the data using the data twig variable in the rendered template.
To make power mails error messages accessible for screenreaders I have to change HTML.
Original Powermail
<div class="form-group powermail_fieldwrap_name has-error">
<label for="powermail_field_name">Name<span class="mandatory">*</span></label>
<input required="required" data-parsley-required-message="Dieses Feld muss ausgefüllt werden!" data-parsley-trigger="change" class="form-control " id="powermail_field_name" type="text" name="tx_powermail_pi1[field][name]" value="" data-parsley-id="12">
<ul class="help-block filled" id="parsley-id-12"><li class="parsley-required">Dieses Feld muss ausgefüllt werden!</li></ul>
</div>
Accessible
<div class="form-group powermail_fieldwrap_name has-error">
<label for="powermail_field_name">Name<span class="mandatory">*</span></label>
<input required="required" data-parsley-required-message="Dieses Feld muss ausgefüllt werden!" data-parsley-trigger="change" class="form-control " id="powermail_field_name" type="text" name="tx_powermail_pi1[field][name]" value="" data-parsley-id="12" aria-describedby="parsley-id-12">
<ul class="help-block filled" id="parsley-id-12"><li class="parsley-required">Dieses Feld muss ausgefüllt werden!</li></ul>
</div>
In short: I have to add aria-describedby="parsley-id-12" to <input>.
In my own version of Ext:powermail/Resources/Private/Partials/Form/Field/Input.html I changed additionalAttributes to additionalAttributes="{aria-describedby:'error',vh:Validation.ValidationDataAttribute(field:field)}"
Complete partial
{namespace vh=In2code\Powermail\ViewHelpers}
<div class="powermail_fieldwrap powermail_fieldwrap_type_input powermail_fieldwrap_{field.marker} {field.css} {settings.styles.framework.fieldAndLabelWrappingClasses}">
<label for="powermail_field_{field.marker}" class="{settings.styles.framework.labelClasses}" title="{field.description}">
<vh:string.RawAndRemoveXss>{field.title}</vh:string.RawAndRemoveXss><f:if condition="{field.mandatory}"><span class="mandatory">*</span></f:if>
</label>
<div class="{settings.styles.framework.fieldWrappingClasses}">
<f:form.textfield
type="{vh:Validation.FieldTypeFromValidation(field:field)}"
property="{field.marker}"
placeholder="{field.placeholder}"
value="{vh:Misc.PrefillField(field:field, mail:mail)}"
class="powermail_input {settings.styles.framework.fieldClasses} {vh:Validation.ErrorClass(field:field, class:'powermail_field_error')}"
additionalAttributes="{aria-describedby:'error',vh:Validation.ValidationDataAttribute(field:field)}"
id="powermail_field_{field.marker}" />
</div>
</div>
This ends with
The argument "additionalAttributes" was registered with type "array",
but is of type "string" in view helper
"TYPO3\CMS\Fluid\ViewHelpers\Form\TextfieldViewHelper"
I can't found a solution in templates because error id is set by parsley validation. So I add this jQuery JavaScript. Because I override some powermail templates jQuery selectors can vary.
$('form[data-parsley-validate]').parsley().on('form:error', function() {
var errorId;
$.each(this.fields, function(key, field) {
if (field.validationResult !== true) {
switch (field.$element.attr('type')) {
case 'radio':
errorId = field.$element.closest('.powermail_radio_group')
.children('.powermail_field_error_container')
.children('ul').attr('id');
break;
case 'checkbox':
errorId = field.$element.closest('.powermail_checkbox_group')
.children('.powermail_field_error_container')
.children('ul').attr('id');
break;
default:
errorId = field.$element.next('ul').attr('id');
}
field.$element.attr('aria-describedby',errorId);
}
});
});
You may use the data-attribute like data="{describedby: 'error'}"
It seems to be fixed in the current parsley.js version 2.9.1. Parsley is now adding the described-by attribute.
the problem is described in this pull request: https://github.com/guillaumepotier/Parsley.js/pull/1280
The current Powermail version 7.3.1 is coming with the outdated parsley version 2.7.2. So you have to add the current parsley.js version by your own.
i am new to zend i have coded up to some extent but dont know further how to decorate my form using decorators etc
this is my old HTML
<div class="col_6 pre_3 padding_top_60" style="padding-top:0">
<div class="widget clearfix">
<div class="widget_inside">
<p class="margin_bottom_15">Kindly enter Username and Password.</p>
<span><?= $this->error;?></span>
<form method='post' action='<?php echo $this->url(array(), 'login') ?>' onsubmit="return validateForm();">
<div class="form">
<div class="clearfix" id="div_username">
<label class="lable-2">Username</label>
<div class="input">
<input type="text" class="xlarge" name="username" id="username" value="<?php echo $this->form['username'] ?>"/>
<span id="error_message_username"></span>
</div>
</div>
<div class="clearfix" id="div_password">
<label class="lable-2">Password</label>
<div class="input">
<input type="password" class="xlarge" name="password" id="password" value="<?php echo $this->form['password'] ?>"/>
<span id="error_message_Password"></span>
</div>
</div>
<div class="clearfix">
<label></label>
<div class="input">
<input type="checkbox" name="remember" value="1" <?php echo ($this->form['remember'] == 1)?'checked="checked"':'' ?>/></span> Stay signed in
<span style="margin-left:10px">Forgot User ID or Password </span>
</div>
</div>
<div class="clearfix">
<label></label>
<div class="input">
<input type="submit" value="Login" class="medium button blue blue-1"/>
</div> </div>
</div>
</form>
</div>
</div>
This is my Form
<?php
class Application_Form_Loginform extends Zend_Form{
public function init()
{
/* Form Elements & Other Definitions Here ... */
$this->setMethod('post');
$this->addElement('text','username',array(
'label' => 'UserName :',
'required' => true,
'filters' => array('StringTrim')
));
$this->addElement('password','password',array(
'label' => 'Password',
'required' => 'true',
'filters' => array('StringTrim')
));
$this->addElement('submit','submit',array(
'ignore'=>'true',
'label'=>'Login'
));
}
}
Question is How can i make my form made with php equal to the above HTML ??
Zend Form is a pain to use, especially decorators.
You should use the View Script decorator instead.
See here: http://framework.zend.com/manual/en/zend.form.standardDecorators.html#zend.form.standardDecorators.viewScript
Aside from Zend Form decorators having a high learning curve, it mixes view code with logic and validation code.
This is not a good thing, especially if you have frontend developers styling and working with the forms.
It also makes prototyping the look of the forms difficult since you have to keep adjusting the decorator code.
With that said, Zend Form does a good job of making validation relatively painless. But one other gripe with it is that I don't think it fits well model validation.
I agree that decorators are complex, but they save a GREAT DEAL of time, when you know how to use them. We use them for our admin panel. We recently changed it from table layout to few fieldsets and divs and it took only few hours to change 70+ forms.
Your validators should be something like:
Form:
form,
htmlTag (div, class=form)
formElements
Elements:
viewHelper
error, placement => append
htmlTag (div, class input)
Label, placement => prepend
htmlTag (div, class=clearfix)
just keep in mind you need to set different keys for each htmlTag decorator, or else they would be overwritten. Like this:
....
array('inputHtmlTag' => 'htmlTag, array('tag' => 'div', 'class' => 'input'),
....
To see how I deal with complex Twitter Bootstrap decorators see https://github.com/tomasfejfar/Zend-Form-Bootstrap/blob/master/library/Bootstrap/Form.php There you can find clues how to implement your own markup.
I want to update the value from a input/textfield with a calculated value from the cookie.It's like a mini local cookie cart.
Saving and retrieving the json from the cookie is a piece of cake.
In my behavior I fail to make the following work:
I added a class for every node in the input field, it's constructed like the example below.
Myid = 'webform_cart_nid_10';
formElement = $('.' + Myid);
console.log(formElement);
The html is quite nested and can be seen http://it2servu.be/broodjes/bestellen (if I may link?) .
the field whose value I want to update looks like this:
<input class="webform_cart_nid_10 webform_cart_nid form-text" type="text" id="edit-submitted-cart-item-cart-elements-10" name="submitted[cart_item][cart_elements][10]" value="0" size="3" maxlength="128">
Is contained in drupal output with severe div-itis.
<div class="page clearfix" id="page">
<div id="section-content" class="section section-content">
<div id="zone-content-wrapper" class="zone-wrapper zone-content-wrapper clearfix">
<div id="zone-content" class="zone zone-content clearfix container-12">
<div class="grid-12 region region-content" id="region-content">
<div class="region-inner region-content-inner">
<div class="block-inner clearfix">
<div class="content clearfix">
<div class="node node-webform node-promoted view-mode-full clearfix ">
<div class="field field-name-title field-type-ds field-label-hidden">
<form class="webform-client-form" enctype="multipart/form-data" action="/broodjes/bestellen" method="post" id="webform-client-form-5" accept-charset="UTF-8">
<div>
<fieldset class="collapsible form-wrapper collapse-processed" id="edit-submitted-cart-item-cart-elements">
<div class="fieldset-wrapper">
<div class="form-item form-type-textfield form-item-submitted-cart-item-cart-elements-10">
<input class="webform_cart_nid_10 webform_cart_nid form-text" type="text" id="edit-submitted-cart-item-cart-elements-10" name="submitted[cart_item][cart_elements][10]" value="0" size="3" maxlength="128">
...
probably it's something stupid, I just can't figure out what it is?
Your problem is with jQuery. If you pop open the console in Chrome and type jQuery, it returns the jQuery function. If you type $ it returns undefined. You have some sort of collision causing $ not to be set to jQuery.
use "jQuery" instead of "$"
Myid = 'webform_cart_nid_10';
formElement = jQuery('.' + Myid);
console.log(formElement);
the "$" never worked for me in Drupal 7.