I have config for google map in my TCA
'configuration_map' => array(
'exclude' => 0,
'label' => 'Map',
'config' => array(
'type' => 'user',
'userFunc' => 'Vendor\\Extension\\Utility\\LocationUtility->render',
'parameters' => array(
'lng' => 'lng',
'lat' => 'lat',
'address' => 'address',
),
),
),
I need same config in flexform, like example below. How set userFunc "parameters" in xml?
<settings.map>
<TCEforms>
<label>Map</label>
<config>
<type>user</type>
<userFunc>Vendor\Extension\Utility\LocationUtility->render</userFunc>
<parameters>
</parameters>
</config>
</TCEforms>
</settings.map>
It should be:
<settings.map>
<TCEforms>
<label>Map</label>
<config>
<type>user</type>
<userFunc>\Vendor\Extension\Utility\LocationUtility->render</userFunc>
<parameters>
<lng>lng</lng>
<lat>lat</lat>
<address>address</address>
</parameters>
</config>
</TCEforms>
</settings.map>
By the way, you should start a namespace with a \
Related
I want to insert a div before my submit button.
->add('address',new AddressForm(array(
))
->add('Valider', 'submit', array(
'attr' => array('class' => ' btn btn-lg btn-success btn-bloc')
))
->add('Cancel', 'reset', array(
'attr' => array('class' => ' btn btn-lg btn-cancel btn-bloc')
))
This the div proposed by Google:
<div class="g-recaptcha" data-sitekey="***************************"></div>
I'm using Twig I did manage to add it after the Form but not inside it.
Any suggestions will be appreciated.
I used the EWZ bundle to add googles recapture to my forms
https://github.com/excelwebzone/EWZRecaptchaBundle
With that bundle you can just add "->add('recaptcha', 'ewz_recaptcha')" to your form builder, for example:
$builder->add('name', 'text', array(
'attr' => array(
'placeholder' => 'Name',
'pattern' => '.{4,}' //minlength
)
))
->add('email', 'email', array(
'attr' => array(
'placeholder' => 'Email'
)
))
->add('company', 'text', array(
'attr' => array(
'placeholder' => 'Company/Organisation',
'pattern' => '.{3,}' //minlength
)
))
->add('message', 'textarea', array(
'attr' => array(
'cols' => 90,
'rows' => 10,
'placeholder' => 'Leave a message...'
)
))
->add('recaptcha', 'ewz_recaptcha')
->add('save', 'submit', array(
'label' => 'Submit',
'attr' => array (
'class' => 'submit btn-block btn-lg btn-primary'
)
));
I create in Zend a nawe field (radio):
$sizeId = $this->createElement('radio', 'size_id');
But i need get in view code looks like this:
<li>
<input ...>
<label><span>name</span></label>
</li>
How to do it?
I did this code:
$sizeId = $this->createElement('radio', 'size_id', array(
'decorators' => array(
'ViewHelper',
array(array('AddTheLi' => 'HtmlTag'), array('tag' => 'li')),
array(array('AddTheUl' => 'HtmlTag'), array('tag' => 'ul', 'class' => 'size-picker clearfix')),
'Errors',
array('Description', array('tag' => 'p', 'class' => 'description')),
),
'disableLoadDefaultDecorators' => true,
'separator' => '</li><li>',
'class' => 'attribute-radio',
));
But no the code in view looks like this:
<li>
<label><input ...>name</label>
</li>
Why the input is in label?
Hi all I'm trying to render this html structure with Zend :
<div id="medias" class="item">
<h2> Medias </h2>
<a id="addmedia" href="#">
<img alt="" src="images/bigbtn-add.png">
</a>
</div>
Update 1 :
This is how I create the media_img element :
$media_img = new Zend_Form_Element_Image('media_img');
$media_img->setImage("/img/bigbtn-add.png");
$this->addElement($media_img);
Using this :
$this->setElementDecorators(array(
'ViewHelper',
'HtmlTag', array('HtmlTag', array('tag' => 'a', 'id' => 'addmedia','href' => '#'))
),
array('media_img')
);
I properly render this part of my code :
<a id="addmedia" href="#">
<img alt="" src="images/bigbtn-add.png">
</a>
How can I prepend the h2 and then wrap these elements inside my div ?
Update 2 :
Thanks to #Mubo's help, I render this html :
<h2 class="hint">Medias</h2>
<a id="addmedia" href="#">
<input id="media_img" type="image" src="/img/bigbtn-add.png" name="media_img">
</a>
Now I only need to wrap all of these lines in a div.
The decorator looks like this now :
$this->setElementDecorators(array(
'ViewHelper',
'HtmlTag', array('HtmlTag', array('tag' => 'a', 'id' => 'addmedia','href' => '#')),
array('Description', array('tag' => 'h2', 'placement' => 'prepend')),
),
array('media_img')
);
What's missing ?
Thanks for your help.
Update 3 : I still can't figure it out...
You can use setDescription and prepend it with decorator like this.
This is very tricky and not straightforward.
$myElement = new Zend_Form_Element_Text('name');
$myElement->setLabel('Label');
$myElement->setRequired(true);
$myElement->setDescription('Medias');
$myElement->setDecorators( array( 'DijitElement', 'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td')),
array('Label', array('tag' => 'td')),
array('Description', array('tag' => 'h2', 'placement' => 'prepend')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr', 'class' => 'form_row'))
));
$this->addElement($myElement);
Wow, I finally found a solution. Here is my decorator :
$media_img->setDecorators(array(
'ViewHelper',
'Errors',
array('HtmlTag', array('tag' => 'a', 'id' => 'addmedia','href' => '#')),
array('Description', array('tag' => 'h2', 'placement' => 'prepend')),
array(
array('fieldDiv' => 'HtmlTag'),
array(
'tag' => 'div', 'class' => 'item', 'id' => 'medias'
)
)
));
Iam using following code to generate CAPTCHA :
$captcha = $this->createElement('captcha', 'captcha',
array('required' => true,
'captcha' => array('captcha' => 'Image',
'font' => 'resource/fonts/arial.ttf',
'fontSize' => '24',
'wordLen' => '5',
'height' => '50',
'width' => '150',
'imgDir' => 'resource/captcha',
'imgUrl' => 'resource/captcha',
'gcFreq'=>'10',
'dotNoiseLevel' => '10',
'lineNoiseLevel' => '2')));
$captcha->setLabel('Captcha');
Following code is generated:
<label for="captcha-input" class="login_label required">Captcha</label>
<img width="150" height="50" alt="" src="captcha/eb3a592c8b1c7a71b0c7ce5179422be2.png" />
<input type="hidden" name="captcha[id]" value="eb3a592c8b1c7a71b0c7ce5179422be2" id="captcha-id">
<input type="text" name="captcha[input]" id="captcha-input" value="">
<input type="text" name="captcha" id="captcha" value="eb3a592c8b1c7a71b0c7ce5179422be2">
Can someone guide me how can I remove extra input text fields like
<input type="text" name="captcha" id="captcha" value="eb3a592c8b1c7a71b0c7ce5179422be2">
Thanks in advance
It's important to do the
$this->getElement('captcha')->removeDecorator("viewhelper");
after you have enabled the ElementsDecorators (which sets the ViewHelper in the first place - don't delete this, it's required anyway)
For me it looks like this:
$this->setElementDecorators(array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td')),
array('Label', array('tag' => 'td')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
));
$this->getElement('captcha')->removeDecorator("viewhelper");
That input is not "extra" - it's essential.
When the CAPTCHA is validated, the value of that field is used to look up the correct solution to the CAPTCHA, which is then compared against the user's input.
Without that field, your CAPTCHA will break.
Why would you want to remove it in the first place?
You can try this:
$this->getElement('captcha')->removeDecorator("viewhelper");
I had the same problem. Remove the "ViewHelper" decorator and the captcha will render properly.
I would like to get rid of the definition list format of my Zend_Form. This is the layout that I'm going for:
<form>
<p>
<label for="email" class="required">Your email address:</label>
<input type="text" name="email" id="email" value="">
</p>
<p>
<input type="submit" name="submit" id="submit" value="Subscribe">
</p>
<input type="hidden" name="active" value="true" id="active">
<input type="hidden" name="signupDate" value="" id="signupDate">
</form>
What do I need to do to my form in order to get this layout?
class Default_Form_Subscribe extends Zend_Form
{
public function init()
{
$this->setMethod('post');
$this->addElement('text', 'email', array(
'label' => 'Email address:',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array('EmailAddress')
));
$this->addElement('submit', 'submit', array(
'label' => 'Subscribe',
'ignore' => true
));
$this->addElement('hidden', 'active', array(
'value'=>'true'
));
$this->addElement('hidden', 'signupDate', array(
'value' => Zend_Date::now()->toString('YYYY-MM-dd')
));
}
}
Ah, beat me to it... I went with the approach of creating a custom definition that can be applied to specific elements. Also had to reset the decorators on the form itself to remove the default 'dl' wrapper, seems to do exactly what you need:
class Default_Form_Subscribe extends Zend_Form
{
public function init()
{
$this->setMethod('post');
// reset form decorators to remove the 'dl' wrapper
$this->setDecorators(array('FormElements','Form'));
// custom decorator definition for form elements
$customElementDecorators = array(
'ViewHelper',
'Errors',
array(
'Description',
array('tag' => 'p','class' => 'description')
),
array(
'Label',
array('separator' => ' ')
),
array(
array('data' => 'HtmlTag'),
array('tag' => 'p')
)
);
$this->addElement('text', 'email', array(
'label' => 'Email address:',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array('EmailAddress'),
'decorators' => $customElementDecorators
));
$this->addElement('submit', 'submit', array(
'label' => 'Subscribe',
'ignore' => true,
'decorators' => $customElementDecorators
));
$this->addElement('hidden', 'active', array(
'value'=>'true',
'decorators' => array('ViewHelper')
));
$this->addElement('hidden', 'signupDate', array(
'value' => Zend_Date::now()->toString('YYYY-MM-dd'),
'decorators' => array('ViewHelper')
));
}
}
let me add probably a bit shorter way which worked for me just fine:
//after adding all the form elements
//all form elements in a loop
foreach ($this->getElements() as $el) {
$el->setDecorators(
array('ViewHelper', 'Errors', array('HtmlTag', array('tag' => 'p')
);
}
//form itself
$this->setDecorators( array('FormElements', 'Form') );
it seams to me in your case you also should filter out elements by type in search for those which does not need outer html at all
You have to customize your Zend_Form elements's decorators. Check this tutorial.
In your case it will be something similar to this:
$form->setElementDecorators(array(
'ViewHelper',
'Errors',
array('Label', array('tag' => 'label', 'placement' => 'prepend'),
array(array('data' => 'HtmlTag'), array('tag' => 'p')),
));
That sets the decorators for all the form elements. You can as well configure individual elements (like your hidden-s & buttons).
It's possible also to form display groups, and decorate them individually.