Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Form values need to manipulated for xssapi FOR AEM 5.6.1 before getting stored under /content/usergenerated/

Avatar

Level 4

Hi,

I am using AEM 5.6.1
I  need to modify  the values  of  the attribute that get  stored in  the  /content/usergenerated/ for the form fields that gets stored on form submit

I find that there is  a server validation /apps/foundation/components/form/defaults/field/servervalidation.jsp. But i find i cannot use it to change the value attribute that could get stored under  /content/usergenerated/ 

I tried the below /apps/foundation/components/form/defaults/field/servervalidation.jsp for "Country" field and changed the value of Country to cs   but found  that the value submitted using form got stored. please let me how this can be achieved. 


for(final FieldDescription desc : descs) {
        if ( FieldHelper.checkRequired(slingRequest, desc) ) {
            FieldHelper.checkConstraint(slingRequest, slingResponse, desc);
        } 

        if ( desc.isRequired()) {  
         String[] values = request.getParameterValues(desc.getName());  
         // You can check for length of values in the string array/values whatever 
//suits you for required validation.  
 }  
        

        if(desc.getName().equalsIgnoreCase("Country")){
            
            slingRequest.setAttribute("Country","cs");
        }


    }

 

Thanks

3 Replies

Avatar

Level 4

Any inputs from anyone for the above will be helpfull??

Avatar

Level 10

The client or server validation is used to generate a snippet of javascript that will be used on the front side to validate the entered value. Avoid misuse of it.  You should implement custom action type & in  post.POST.jsp  handle the changes required.   Out of the box location reference like /libs/foundation/components/form/actions/<actiontype>/post.POST.jsp

Avatar

Level 4

Thanks Sham for the inputs.

I have custom  form field name  "email" i tried changing its value in forward.jsp

under the below path i the below jsps

/apps/app1/components/form/actions/store
/apps/app1/components/form/actions/store/addfields.jsp
/apps/app1/components/form/actions/store/forward.jsp

the above code is taken from /libs/foundation/components/form/actions/store

in the /apps/app1/components/form/actions/store/forward.jsp we have the existing code

try {
                    final Node node = JcrUtil.createPath(path, "sling:Folder", adminSession);
                    final Node parent = node.getParent();
                    node.setProperty("email","what@abc.com"); // i added the custom  form field that i wanted to get stored under /content/usergenerated/path


                    
but the email value was always overwritten with the actual value i had passed using form.
                    

  1. I   found that FormsHelper.setForwardPath(slingRequest, path, true); was causing this to happen as when i commented this line the email was getting set correctly like i wanted above.
  2. But FormsHelper.setForwardPath(slingRequest, path, true); is always required for the form to show the  results correctly to the user.

From the above could you please tell me as how could i set the "email" value to "what@abc.com"  to be stored in /content/usergenerated/path

Thanks