adobe / aem-core-wcm-components

Standardized components to build websites with AEM.
https://docs.adobe.com/content/help/en/experience-manager-core-components/using/introduction.html
Apache License 2.0
744 stars 750 forks source link

[Forms] Container does not seem to recognize the Endpoint field (aka action) #1436

Open knennigtri opened 3 years ago

knennigtri commented 3 years ago

Expected Behaviour

When using the post form data actiontype, I should be able to set the action attribute of the form. The result should be:

<form method="POST" action="/location/to/my/endpoint/url.json" id="new_form" name="new_form" enctype="multipart/form-data" class="cmp-form aem-Grid aem-Grid--12 aem-Grid--default--12">
    .....
</form>

Actual Behaviour

Actual behavior ends up setting the action the same as the current page:

<form method="POST" action="/content/us/en.html" id="new_form" name="new_form" enctype="multipart/form-data" class="cmp-form aem-Grid aem-Grid--12 aem-Grid--default--12">
    .....
</form>

Reproduce Scenario (including but not limited to)

  1. Create and install a project using the latest archetype
  2. On /content/us/en.html drag and drop a form container
  3. Configure the Form container
    1. ActionType = Post form data
    2. Endpoint = /location/to/my/endpoint/url.json
  4. Add a text form and submit form This could be my limited knowledge of forms, but I think the endpoint should set the action attribute, but this does not seem to occur.

    Platform and Version

    Cloud Service: 2021.2.4944.20210221T230729Z-210128

Logs taken while reproducing problem

Looking deeper into this, the component persists an action property to the JCR as expected. image The HTML and json output have the action value = /content/us/en.html image image

To me this indicates that there might be something wrong with the Sling Model. Based on my limited knowledge on how this ContainterImpl.java works, it seems like the code does not get the action property from the jcr. https://github.com/adobe/aem-core-wcm-components/blob/master/bundles/core/src/main/java/com/adobe/cq/wcm/core/components/internal/models/v1/form/ContainerImpl.java#L102 image

.... image

... image

RyanScott96 commented 3 years ago

Just bumping this thread since I seem to be having this issue as well. Luckily I only need it for testing a Servlet and in the meantime can create an HTML form as a workaround. I'd like to specify that the form action is the page the form exists on rather than the specified endpoint

insideaem commented 2 years ago

@knennigtri @RyanScott96 ok I manage to solve it. Problem was with the CSRFFilter blocking the Post requests. Now it reaches the RPC handler properly.

@vladbailescu, @bpauli Could you please explain to me why it is not possible to post to the API endpoint directly from the browser? In our case we have an API endpoint which is public and we do not need the roundtrip through AEM.

So what we want is to be able to configure the API endpoint in the form component dialog and have the html form action attribute point to that endpoint instead of a resource in AEM.

I imagine we could have an additional actionType client-side. And in that case the form will output the configured endpoint directly in the form action?

Thanks for your support.