I have written a plugin whose job is to create a custom page with a user subscription form. The form page is created like this:
$page = [
'post_type' => 'page',
'post_content' => '',
'post_status' => 'publish',
'post_title' => 'Create a new account',
'post_name' => 'account new'
];
$page_id = wp_insert_post($page);
This creates a new page at http://example.com/account-new/
that renders a subscription sign up form. I used the same process to create a page that receives the POST data at http://example.com/account-pending/
.
In my theme, which is independent of the plugin, the form's opening tag looks like this:
<form method="post" id="new-account-form" action="/account-pending/">
On submit, I can see in Chrome that the post data are sent to the account-pending page, but when I debug the PHP code with PHPStorm I find that the $_POST object is not set.
The /account-pending/
page contains the following function that is meant to process the POST data:
public function get_account_pending()
{
if (isset( $_POST['my_check_value'])) {
$username = $_POST['username'];
$password = $_POST['userpass'];
$firstname = $_POST['firstname'];
etc...
I have also added an action for capturing the post action with
add_action( 'wp', array( &$this, 'get_account_pending' ) );
but I am still missing something. How do I find what is stripping away the $_POST object? At this point in the code only the following variables are set:
$this
$_GET
$_REQUEST
$_SERVER
$GLOBALS
Am I missing a step somewhere that is required to properly set up the POST data for receiving it on the /account-pending/
page?
Edit:
I am able to see the $_POST data if I send the data via a cURL command as below:
curl -X POST 'firstname=myfirst' -F 'lastname=mylast' -F 'username=username21' -F 'usermail=me%40example.com' -F 'userpass=thisone' -F 'userpass_again=thisone' -F 'my_check_value=on' -F 'billing_address=452+Kennebec+Rd' -F 'billing_apt=' -F 'billing_city=Heretown' -F 'billing_state=ME' -F 'billing_zip=04444' -F 'card_type=4' -F 'card_number=4111111111111111' -F 'expire_month=07' -F 'expire_year=23' http://example.com/account-pending/?XDEBUG_SESSION_START=10663
This seems to indicate that the problem lies with either wordpress (or PHP) clearing the $_POST variable, or that my form is not submitting the data properly.
&
infront of$this
, it's there to prevent PHP4 breaking, but WordPress hasn't supported PHP4 in years. btw have you eliminated WordPress as a cause? You can test that by submitting to a standalone PHP file that just prints out the POST value, orvar_dump( $_POST );
. Also keep in mind that $_POST is not a normal variable, it's a superglobal&
and updated the question - curl does generate a filled-in $_POST variable. I'm still searching for causes for the lost $_POST.wp
orinit
something likeadd_action("wp", function() { if ( "account-pending" === get_post_field( "post_name", get_the_ID() ) ) { echo var_dump( $_POST ); } });
'cause I doubt it would be successful doing to upon content served (you mentioned "The /account-pending/ page contains the following function that is meant to process the POST data..")..