Confirm password value lost during postback in zend framwork? - zend-framework

I am working with Zend Framework. In my Zend form when there is post back or validation error all the fields contain there values but confirm password lost it's value.How to solve this issue.

By default password fields to not include the submitted value, since doing so somewhat defeats the point of obfuscating the password with *. However you can pass the 'renderPassword' option to the password field to change this behaviour.
There's an example of usage on the patch where the feature was introduced: http://framework.zend.com/issues/browse/ZF-2860

you can try with this option.
you can get the form in view and render all elements one by one like this
and you can set value also.
$confpassword = $this->form->getElement('confpassword');
$confpassword->setValue($_POST['confpassword']);
echo $confpassword;

Related

drupal form textfield name -value changed and does not validate any more

i have a checkout-page (drupal commerce) form with an address section generated by the module addressfield. currently all text-inputfields have this markup-structure:
<input class="last-name" id="edit-last-name" name="customer_profile_billing[commerce_customer_address][und][0][last_name]">
class + id + name
with this config they validate.
if i change the value of the name attribute the form doesnt validate anymore, the form says:
field XY is required
the form-validator obviously doesnt recognise my inputs.
question: how can i get the validation process to work with a modified name attribute?
You should not be altering the generated HTML in any way. Drupal provides a special way of handling forms and a special way to alter other modules forms. To change the form you should use the configuration options presented to you by the module. If those are insufficient you should create your own Drupal module and then implement hook_form_alter to change the other form. You will need to understand Drupal's hook system.

Hide image field completely in drupal 7 module

I'm trying to setup a form where some fields needs to be hidden depending on the user role. I'm doing this in my own module using hook_form_FORM_ID_alter. No problem with common text, email or link fields (e.g. $form['field_companyname']['und'][0]['value']['#type']='hidden'). But for an image field or a multiple value file field the usual way won't work.
Anybody can give me a clue?
I think your going about this the wrong way. Since your limitation is based on roles you can just use the permissions system. Check out field permissions module.
I recommend you to use #access for the element instead of just hiding the field.
For field company name it will go like this:
$form['field_companyname']['#access'] = FALSE;

HTML5 form validation: Default = invalid, is this normal behavior?

I am building a form using HTML5 form validation.
I have the CSS classes input:valid and input:invalid defined. Some of the input fields are marked as required, but not all of them. Is it normal that the fields that aren't marked as required are valid by default, meaning in my case have a green background? And is it normal that required fields are invalid by default?
If this is normal: Why did they make it that way? In my eyes it is not very user friendly to mark a field as valid oder invalid before something was entered. Is there anything I can do besides JavaScript?
Yes, it's normal behaviour. Whenever user entered anything or not, he should know that field, marked as required, will be invalid until he will enter anything that matches pattern (or just anything :) ).
If for some reason you don't like such behaviour - sorry, but you should use JavaScript.

Zend hidden elements: hide html values

I am facing a special scenario here on some of my forms.
I have settled a permission system over some fields many of which are required.
When removing the permission to view the field on a form, I set:
$field->setDecorators('disableLoadDefaultDecorators', true);
The problem in that case is that I get prompted with the validation error over the required field, which is logical.
The other option would be to set the $field to hidden but the issue turns to become an html problem where any person can retrieve the hidden value through the source code.
Hopefully someone can offer me a suggestion on how to hide the element from the form and metadata but return it on form validation as if it was displayed.
Thank you in advance!
Change the field validation rules so that it is not required:
$field->setRequired(false)->setDecorators('disableLoadDefaultDecorators', true);

I'm not specifying the form action but it (automatically) gives different values in some cases

I'm creating my form using the Form helper, so the action of the form is specified automatically....
this form is used for editing a post..
so, the URL has the structure: mywebsite.com/posts/edit/id
and the form's action should be automatically generated as posts/edit/id
but the problem is, in some cases, I open the HTML code and I find that the form's action is only posts/edit without the id which causes the update to fail...
I spent a lot of time to figure out what situation brings this wrong action:
i'm generating fields dynamically (using javascript & ajax) depending on the post's category..
when the value of one of the dynamically generated fields is invalid, the generated action becomes posts/edit !!
I really need help, cuz I don't know why this is happening !!!
and I don't wanna waste more time digging into the core of cakephp...
so, if any of cakephp experts has an idea about this, plz help me !!
thank you in advance !
Use the url parameter, which allows you to explicitly define a url for the form:
echo $form->create('Post', array('url' => $html->url(array('action'=>'edit', $id))));
It sounds like $id probably isn't getting set, because it should be getting passed along if it is. You need to make sure it's set to edit the record in question. Make sure your javascript is including the hidden field with the record's id in it.
Normally done like this, with the form helper: echo $this->Form->input('id');
Also, if one of the fields is invalid, the form shouldn't actually be submitting properly, if you are using cake's validation, so this is to be expected.