Zend Framework Form Submit Button Style - forms

Is it possible to change the form's Submit button from the defaut - like the Gmail button say, which is blue?
Currently I have this in my form:
$this->addElement('submit', 'form_element_signup', array('label' => 'Sign up',
'tabindex' => 20,
'decorators' => array('ViewHelper',
array(array('div' => 'HtmlTag'),
array ('tag' => 'button',
'class' => 'action blue')))));
But this still gives me the default submit button within my div button.

you can add your custom class with your own css property like below
$this->addElement(new Zend_Form_Element_Button( 'send',
array( 'label' => 'registrieren',
'class' => 'button-red',
'type' => 'submit',
'escape' => false,
'required' => false,
'ignore' => false, ) ));

Yes just apply the appropriate CSS to the 'div', 'tag' or 'class' as required.
22 CSS Button Styling Tutorials and Techniques may help.

Related

How do I allow html tags in label for Zend form element using addElement()?

I am brand new to Zend and I've been given a project to make adjustments on. I'd like to add html to the labels for my form elements but I can't seem to get it right.
Here's what I have:
$this->addElement('text', 'school_name', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 150)),
),
'required' => true,
'label' => 'Name* :<img src="picture.png">,
'size' => '90',
));
As is, of course, the <img src="picture.png"> text gets escaped and the whole string is displayed.
I've read that I need to use 'escape' => false in some capacity but I can't figure out where/how to use it in my specific case.
Any help would be great. Thanks!
After calling addElement fetch the label's decorator and change the escape setting:
$form->getElement('school_name')->getDecorator('label')->setOption('escape', false);
If you use this type of label a lot, you should consider writing a custom decorator.
You can also use the disable_html_escape in 'label_options' when adding an element to the form:
$this->add(array(
....
'options' => array(
'label' => '<span class="required">Name</span>,
'label_options' => array(
'disable_html_escape' => true,
)
),
...
));
Credit to Théo Bouveret's post 'Button content in ZF2 forms' for the answer.

zend form client side validation

I am trying to validate a form created by zend form library. It is validating the form properly, but when I press tab button then its validating all the fields immediately. But it should be validating after press the tab button or press the final submit button.
My code is like:
$this->addElement('text', 'email', array(
'label' => 'Email:',
'required' => true,
'class' => 'span12',
'attribs' => array(
'required' => true,
'pattern'=> "^[A-Za-z0-9._]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$"
)
));
$this->addElement('text', 'name', array(
'label' => 'Name:',
'required' => true,
'class' => 'span12',
'attribs' => array(
'required' => true,
'pattern' => '[a-zA-Z]{4,}'
)
));
$this->addElement('text', 'phone', array(
'label' => 'Phone:',
'required' => true,
'class' => 'span12',
'attribs' => array(
'required' => true,
'pattern' => '\d{4,}'
)
));
Please find the image.
Pressing tab after writing email address, showing red box for name and phone number.

Div Hide/Show with radio button click using Zend Form

Here is my code:
class File_Form_AddFile extends Custom_Form {
public function init() {
$translate = Zend_Registry::get('translate');
$this->setTranslator($translate);
$this->setName("addfile");
$this->setMethod('post');
$this->addElement('text', 'title', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 50)),
),
'required' => true,
'label' => __('Title') . ':',
));
$this->addElement('radio', 'type', array(
'label'=>__('Applicant Type'),
'multiOptions' => array(
'office' => 'Office',
'community' => 'Community',
'person' => 'Person',
),
'required' => true,
'separator' => '',
'value' => 'office'
));
**// I want this section to show only after 'community' is clicked at above input field.**
$this->addElement('radio', 'community_is_registered', array(
'label'=>__('Registered Community?'),
'multiOptions' => array(
1 => 'Yes',
0 => 'No',
),
'separator' => '',
'value' =>'0'
));
$this->addElement('text', 'name', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 100)),
),
'required' => true,
'label' => __('Applicant Name') . ':',
));
$this->addElement('submit', 'save', array(
'required' => false,
'ignore' => true,
'label' => __('Save'),
));
$this->save->removeDecorator('label');
}
}
This is a form to add some information of a file. Here i want to show the section of "Registered Community?" only after the button "Community" is clicked at "Applicant Type". Seeing for help !!
Since you want certain behavior to occur on the client-side based upon certain actions taking place on the client-side, it seems to be fundamentally a client-side question.
Perhaps the easiest thing is to:
Add a certain CSS class to the Registered Community element (or display group, if it's a collection of elements) during server-side form creation.
Use front-end CSS to hide all form elements of that class.
Add a client-side on-click handler to the "Applicant Type" element that removes/changes the class or shows/hides the "Registered Community" section when the "Applicant Type" has the desired value.

onblur function call in zend framework add element

I am new to fend framework. I have a input box in html with on blur property which call a ajax function code is given below:
input name="companyCode" type="text" id="companyCode" style="width:220px"
onblur="getOrganizationode(this.value);"
and a ajax script tags.
Basically i want my input box in Zend form with onblur function call in Add element function like this
addElement( 'text', 'companyCode' , array(
'required' => true,
'filters' => array('StringTrim'),
'style' => array('width:220px'),
so please help me
You can just add the call to the attributes:
addElement('text', 'companyCode', array(
'required' => true,
'filters' => array('StringTrim'),
'style' => array('width:220px'),
'onBlur' => 'getOrganizationode(this.value);'
);

How can I render label to the right of the element?

I am adding a consent checkbox to an existing form. I am not able to render the label to the right of the checkbox. What am I doing wrong?
Please note that the check box has created using $this->addElement( because the rest of the form was created this way.
I thank you in advance.
$this->addElement('checkbox', 'isUserConsent', array(
'options' => array(array('placement' => 'APPEND')),
'label' => 'Plz activate',
'validators' => array(
array('InArray', false, array(
'hay' => array(1),
'messages' => 'Please check the consent box'),
)
),
'decorators' => array('ViewHelper','Errors','Label'),
));
The default is to prepend the label, but you can change this by modifying the decorator's 'placement' option:
$this->getElement('isUserConsent')->getDecorator('label')->setOption('placement', 'append');
Edit: I never use this syntax for decorators but it should be something like this:
$this->addElement('checkbox', 'isUserConsent', array(
'options' => array(array('placement' => 'APPEND')),
'label' => 'Plz activate',
'validators' => array(
array('InArray', false, array(
'hay' => array(1),
'messages' => 'Please check the consent box'),
)
),
'decorators' => array(
'ViewHelper',
'Errors',
'Label' => array(
'placement' => 'append'
)
),
));
This is the code for rendering lable of a form element.
$this->form->name->renderLabel() ;