I have created a form in aem using core form container and have defined two fields username and password.I want to get this data inside a servlet.
Views
Replies
Total Likes
Hi @janhavi_singh ,
Have you tried request.getParameter() method ?
String userName = request.getParameter("userName"); String password = request.getParameter("password");
we usually use getParamter() only, could you please check?
I tried using request.getParameter but still can't data from Form
Could you please share your servlet code?
I have created a form which looks like this and have passed the endpoint for the servlet in the core form container
Please check the name in the form field dialog as shown in the below image is matching with your request parameter name or not. This might be a reason for this.
If this is also not the case, then check for the servlet call while submitting the form in network tab from developer console and see what is the payload for that.
Regards,
Sravani
If you POST data to an external endpoint, extract multipart/form-data using request.getParts
Refer to sample https://experienceleague.adobe.com/docs/experience-manager-learn/forms/handling-af-form-submissions/...
HTH.
I think this method is valid only for the adaptive forms and not the core form container component of AEM
Noted! I missed that. I would suggest checking service user permissions.
Hi,
How does your form HTML looks like?
I am using core form container and have not made any changes in the html .
Can you check if the input fields has the values and name attribute when form is submitted
<div class="container responsivegrid"> <form method="POST" action="/content/core-components-examples/library/core-form/form-text.html" id="new_form" name="new_form" enctype="multipart/form-data" class="cmp-form aem-Grid aem-Grid--12 aem-Grid--default--12"> <input type="hidden" name=":formstart" value="/content/core-components-examples/library/core-form/form-text/jcr:content/root/responsivegrid/demo/component/container"> <input type="hidden" name="_charset_" value="utf-8"> <div class="text aem-GridColumn aem-GridColumn--default--12"> <div class="cmp-form-text"> <label for="form-text-991299145">Name</label> <input class="cmp-form-text__text" data-cmp-hook-form-text="input" type="text" id="form-text-991299145" placeholder="Please enter your name" name="firstName"> </div> </div> <div class="text aem-GridColumn aem-GridColumn--default--12"> <div class="cmp-form-text" data-cmp-required-message="You need to add your email to log in"> <label for="form-text-2014401237">E-Mail</label> <input class="cmp-form-text__text" data-cmp-hook-form-text="input" type="email" id="form-text-2014401237" placeholder="Please enter your E-Mail" name="email" required=""> </div> </div> <div class="text aem-GridColumn aem-GridColumn--default--12"> <div class="cmp-form-text"> <label for="form-text-1948726228">Message</label> <textarea class="cmp-form-text__textarea" data-cmp-hook-form-text="input" id="form-text-1948726228" placeholder="Please enter your message" name="textarea" rows="2"></textarea> </div> </div> </form> </div>
Hi @janhavi_singh,
By default Core Form Container is not supporting any additional servlets to handle POST request. It is handled by com.adobe.cq.wcm.core.components.internal.servlets.CoreFormHandlingServlet.
I am assuming that your custom servlet is never called, when you are submit your form. If you want to use your custom servlet registered under specific path, you will need to customize /apps/core/wcm/components/form/container/v2/container and do some modification in container.html. By some modification, I mean to set attribute action to point to your servlet path, e.g.
<!--/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ Copyright 2016 Adobe ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/--> <form data-sly-use.container="com.adobe.cq.wcm.core.components.models.form.Container" data-sly-use.grid="com.day.cq.wcm.foundation.model.responsivegrid.ResponsiveGrid" method="${container.method}" action="/bin/servlets/registration-form" id="${container.id}" name="${container.name}" enctype="${container.enctype}" class="cmp-form ${grid.cssClass}"> <div data-sly-test="${container.errorMessages}" data-sly-list.item="${container.errorMessages}" class="cmp-form-error"> <p class="cmp-form-error__item">${item}</p> </div> <input type="hidden" name=":formstart" value="${resource.path}"/> <input type="hidden" name="_charset_" value="utf-8"/> <input data-sly-test="${container.redirect}" type="hidden" name=":redirect" value="${container.redirect @ extension='html'}"/> <sly data-sly-repeat.paragraph="${grid.paragraphs}" data-sly-resource="${paragraph.path @ resourceType=paragraph.resourceType, decorationTagName='div', cssClassName=paragraph.cssClass}"></sly> <sly data-sly-resource="${resource.path @ resourceType=container.resourceTypeForDropArea, appendPath='/*', decorationTagName='div', cssClassName='new section aem-Grid-newComponent'}" data-sly-test="${wcmmode.edit || wcmmode.preview}"></sly> </form>
In below thread I have described step by step 2 scenarios how to extend Form Core Container:
I think you should consider to create your own form container component in case you do not want to use OOTB servlet and it's functionalities. It will be much simpler to control entire form flow.
I have created custom action using the above link and even tried changing the action to "bin/servlet/registration-form", still no success, could you please tell how to call servlet in the post.POST.jsp file as the getServlet method is deprecated now.
Views
Likes
Replies
Views
Likes
Replies