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

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.

Related

How to cross-validate contact form 7 form fields?

I want to make two sperate check box groupe. Lets say
Front end courses
-Bootstrap
-React Js
-Angular js
Back end courses
-C#
-Node
-PHP
on submitting form I want to make sure at least one course is selected by the user. Lets say a student selects ReactJs.
I have tried below code but it makes one option mandatory for all checkbox groups
[Checkbox* checkbox-11 ",Bootstrap" "React Js" "Angular JS"]
[Checkbox* checkbox-12 ",C#" "Node" "PHP"]
How can I make at least one option selected mandatory from any of the checkbox groups
field validation takes place post form submission. To solve this problem you need to make neither field mandatory, and then do a custom validation on the server side. CF7 plugin allows you to add custom validation to individual field but does not allow you to validate a field wrt to the value of other fields in the form.
To do this you need an extension such as the Smart Grid-layout plugin which has a validation hook that gives you access to the entire form's submitted data and therefore cross-validate your fields,
add_filter('cf7sg_validate_submission', 'cross_validate_submission',10,3);
function cross_validate_submission($validation, $submission, $form_key){
if(empty($submission['fe-courses']) && empty($submission['be-courses'])){
$validation['fe-courses']='You need to select at least 1 course!';
}
return $validation;
}

Kentico 9 macro for form field visibility

I have a custom page type, and the editor will have the option to enter the following
Image (from media library)
Video (from media library)
YouTube video ID
The field names are as follows
SlideImage
SlideVideo
YouTubeVideoID
So, if an editor ads a SlideImage, SlideVideo and YouTubeVideoID should not be usable. Same for SlideVideo and YouTubeVideoID.
Within the Visibility Condition fields, i'm going to assume a macro is needed for this. My logic is:
This field visible if Field A or B have data.
A possible approach can be to add an additional field, which determines the field that should be used.
Create a text field (let's say, SlideType) and use a radio button form control with your options:
image;Image
video;Video
youtube;YouTube
Tick the "Has depending fields" checkbox for this field, and tick the "Depends on another field" checkbox for the SlideImage, SlideVideo and YouTubeVideoID fields.
Your visibility conditions would then be simplified, instead of checking the values of multiple fields.
For example, the visibility condition for the SlideVideo field would be:
SlideType == "video"
This has a few benefits:
Easy to add new fields and configure the visibility conditions
Easy to check what needs to be rendered in the front-end - in your repeaters and other webparts, you can simply have conditional statements on the SlideType field to determine which field to use
Intuitive for the end user - the interface makes it clear which field is being used
Add this to Visibility condition in Page type field edit:
Fields.SlideImage.Value == String.Empty
Do not forget to set proper Has depending fields and Depends on another field properties depending on your needs. You can learn more about these properties here.
Let's say the column name on which this value of your depending field is "FirstName", so you can write in the dependent field -> Visibility Condition as
FirstName.value != ""
or
FirstName.value
You can twist the conditions for as many conditions as possible and can club more than one condition too.
I am also sharing links with you having a lot of examples from Kentico support
Dependency fields in Kentico
Using dependency fields in forms
Cheers,
Chetan

Drupal 7 - Hide certain form fields of a content edit form depending on the content data

In Drupal 7, is there a way to change the standard edit form for a content type based on a certain content?
For example:
I have a content type with a checkbox...once it it checked and the form is saved, I do not want this checkbox to be visible anymore...therefore based on the checkboxes value in the Database I want to hide form fields when showing the form.
I am building a small specific project site, where a company wants to add projects, and their customers are supposed to follow certain steps (upload some content, provide information etc.), and also should be able to check off certain requirements, and once these are checked off, they should not be visible/editable to them.
Also the displayed form fields should depend on an user's role, and then FURTHER be limited depending on the content's database entries.
Is there a module, which could achieve this behaviour? "rules" and "field/permissions" come close to what I need, but are not sufficient. Or did I just miss the option to change a form field's accessibility based on conditions?
What I need is some place to define a logic like "IF (VALUEOF(CHECKBOX_1) == TRUE) THEN DO_NOT_SHOW(CHECKBOX_1)"
hook_form_alter is the way to do this, as explained by Mihaela, but what options do you have inside that function?
If you want just to disable field (it will be visible, but user can't change it) you can do it like this:
$form['field_myfield']['#disabled'] = TRUE;
And if you want it to be hidden, but to keep value it has before editing the way to do that is:
$form['field_myfield']['#access'] = FALSE;
I.e. hiding it (somewhere I saw someone suggesting that):
hide($form['field_myfield']);
really hides the field, but after that, when form is saved this field has empty value, validation fails, etc, so that's not a good way to do this. Hiding makes sense only if you want to print separately that field later, at some other place.
function your_module_form_alter(&$form, &$form_state, $form_id){
switch($form_id) {
case 'nameOfTheNode_node_form':
//your code here. check the value from from_state.
break;
}
}
In this case, I use module Conditional Fields https://www.drupal.org/project/conditional_fields
For example: If my Dependees field has a value, Dependent field can be visible/invisible, enabled/disabled, required/optional, checked/unchecked

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

Zend form change elements required options to false at runtime

I have a form and having two file upload elements. it is like
$data_file_one = $this->createElement('file','data_file_one');
$data_file_one->setRequired(true)
->addValidator('Extension', false, 'csv')
->setDestination($filepath);
Both are set to required true. I use the same form for new post and edit posts. When it is used for editing the file upload should not be mandatory and must be set to required false. So, I need to change
setRequired(true) to setRequired(false)
How can I do when edit action is called to load form and change this element option?
Thanks in advance.
Zend_Forms have a method called getElement that allow you to retrieve an element from a form by its name. This gives you the ability to modify an element's default value before rendering it to the user.
For example, to change a field from being required to being optional, you can do the following:
$form->getElement('data_file_one')->setRequired(false);