Expand my Community achievements bar.

SOLVED

Getting undefined index when submiting data to php

Avatar

Level 2

Hello!

I'm stuck for 2 days now on this situation:

I made 2 forms with AEM Designer - Forms and i am saving data that is being filled in them into a mysql database using php. 

To submit data i am using the same php script for both of them and the same HTTP Submit button, yet, when i press the button, for one of the forms the data saves correctly and for the other one i am just getting the 'undefined index' message for all fields in it and var_dump($_POST) for it is empty...

The differece between the 2 forms is that the second one that is not saving, has few more fields in it, rest is the same.

Also the encoding for both forms is UTF-8.

What am i missing? is it there another property of the form that is should check?

Pls help! 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @CilonX,

Your POST request is being filtered and restricted by the “Apache Sling Referrer Filter” and “Adobe Granite CSRF Filter”. By default, the Apache Sling Referrer Filter blocks any incoming POST requests, and the Adobe Granite CSRF Filter blocks any incoming POST requests without the CSRF-Token token in the header.

You can solve this by following below steps

  • Allow incoming POST request in the Apache Sling Referrer Filter OSGI configurations, and
  • Remove the requirement of the CSRF-Token in the Adobe Granite CSRF Filter OSGI configurations.

Steps:

Configure Apache Sling Referrer Filter:

  1. Enable allow empty
  2. Remove the POST method from filters

In OSGI configurations (http://localhost:4502/system/console/configMgr), locate “Apache Sling Referrer Filter”. Enable the allow empty property, and remove the post method from filters property.

SantoshSai_0-1669520456500.png

Configure Adobe Granite CSRF Filter

  1. Remove the POST method from filters

In OSGI configurations (http://localhost:4502/system/console/configMgr), locate “Adobe Granite CSRF Filter”. Remove the post method from filters property.

SantoshSai_1-1669520456565.png

Note: After making configurations to the two OSGI configurations, you should be able to make a POST request from your HTTP REST Client to your AEM instance.

For production, set Apache Sling Referrer Filter and Adobe Granite CSRF Filter settings back to default. Unless if you are giving access to other servers to make POST requests to your AEM application.

Hope that helps you!

Regards,

Santosh

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @CilonX,

Your POST request is being filtered and restricted by the “Apache Sling Referrer Filter” and “Adobe Granite CSRF Filter”. By default, the Apache Sling Referrer Filter blocks any incoming POST requests, and the Adobe Granite CSRF Filter blocks any incoming POST requests without the CSRF-Token token in the header.

You can solve this by following below steps

  • Allow incoming POST request in the Apache Sling Referrer Filter OSGI configurations, and
  • Remove the requirement of the CSRF-Token in the Adobe Granite CSRF Filter OSGI configurations.

Steps:

Configure Apache Sling Referrer Filter:

  1. Enable allow empty
  2. Remove the POST method from filters

In OSGI configurations (http://localhost:4502/system/console/configMgr), locate “Apache Sling Referrer Filter”. Enable the allow empty property, and remove the post method from filters property.

SantoshSai_0-1669520456500.png

Configure Adobe Granite CSRF Filter

  1. Remove the POST method from filters

In OSGI configurations (http://localhost:4502/system/console/configMgr), locate “Adobe Granite CSRF Filter”. Remove the post method from filters property.

SantoshSai_1-1669520456565.png

Note: After making configurations to the two OSGI configurations, you should be able to make a POST request from your HTTP REST Client to your AEM instance.

For production, set Apache Sling Referrer Filter and Adobe Granite CSRF Filter settings back to default. Unless if you are giving access to other servers to make POST requests to your AEM application.

Hope that helps you!

Regards,

Santosh