Zend hidden elements: hide html values - forms

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);

Related

Parsley.js - Re-validate a field after selecting an auto-complete value or drag-and-drop

After parsley validation, an error message may be displayed near a field.
If the user types a corrected value, the field is automatically re-validated, the message will disappear, and the field will be marked with success.
However, if a valid value is then entered by either i) selecting from the field's "auto-complete" dropdown OR ii) by dragging-and-dropping into the field, this will not invoke the re-validation, and the error message remains even though the field now has a valid value.
Example...
Q: How to force fields to re-validate upon selecting value from the browser's auto-complete dropdown/drag-and-drop?
(I realise you can specify no auto-complete on fields, but this may not always be desirable, and doesn't solve the drag-and-drop issue.)
In autofill function add this code to validate the autofill fields again:
function autofill_function_name(){
your code;
$("#autofill_field_name").parsley().validate();
}
In my case, I use bootstrapValidator for validation.
Then, you have to revalidate the field after fetching data
$('yourForm).bootstrapValidator('revalidateField', 'inputName');

InfoPath 2010 How to avoid validation when a section is hidden?

I am trying to design an info path form that links to a share point list.
I have a "extra" section on the form which is only visible if a check box value = true.
The problem is some of the fields on the "extra" section is mandatory. So when the check box value = false, the section is hidden and I cannot fill in the fields. But when I try to submit the form I get an error message to say mandatory fields must be completed. But I do not want to complete those fields.. as the section is to be kept hidden.
Any suggestion on how to get this working would be very helpful thanks.
Do not add the required field checkbox instead create a validation rule that checks if your value is true and the hidden field is empty then send a required error.
This way you can submit the form.
put a sample value on that field like "none" then when the section is checked, set a rule that will clear that field.

Confirm password value lost during postback in zend framwork?

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;

Symfony2 access all form errors without form_bubbling

I want to know if it is possible to access all of my form's errors without using form_bubbling since it gives the error to the parent and individual objects loose their error...I need both the form to know globally if there are errors to display a global "please fix your errors" message and the individual elements to know if they contain errors because I will add an error CSS class to invalid form inputs.
Thanks in advance!
Most efficient way I found to get the numbers of errors of a form, regarless its form_bubbling is trueor false is to add, in the controller, some variable indicating it :
return $this->render('Acme:Contrats:index.html.twig', array(
'myform' => $form->createView(),
'myformHasErrors' => !$form->isValid(),
));
If anyone find another one, please comment/answer this.
After speaking to people in Symfony's IRC channel, there exists two ways to do this in a Twig template:
form.has('errors') for a boolean stating whether or not the form contains errors.
form.vars.errors|length for the number of errors contained in the form.
Problem solved. All of this can be used without using error_bubbling.

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.