I have an admin page in my plugin that contains a form which is to submit to a custom table created during plugin activation. Here is how I went about it:

The following php and html codes are placed on that plugin page.

//php code to receive form data and submit to table goes here

<form method="post" action="">

It works, but what is a better method of doing this, especially with Ajax.


[UPDATE] You should have the page divided in two section- 1. One dealing with AJAX request and Post Method 2. Displaying form data

Here is outline


if (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'  or $_SERVER['REQUEST_METHOD'] == 'POST'){
// Process AJAX Request or POST Method
if (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest'){
// HTML Code here which will not be returned to AJAX Call

As html code will be returned with ajax response that will cause trouble if not filtered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.