首页 > 解决方案 > I can not access a POST within my class in PHP

问题描述

I have an HTML form with method = "POST" and a submit button. Within my file 'purchases.controller.php', if I do a var_dump ($_POST), you can see all my POST variables belonging to the inputs of the form correctly.

Now, I have another file called 'aux.php' which gets an array by AJAX and then I pass it to a function of a class in the file 'purchases.controller.php'. There, I want to manipulate the array and the POST variables that are arriving, but it only allows me to manipulate the array, the POST within the function do not exist.

Does anyone know what I'm doing wrong?

I share the purchases.controller.php code:

//HERE SHOWS ME THE POST VARIABLES AS THE 'registroUsuario', ETC.
var_dump($_POST)

    class Purchases {

        public function ctrCash(&$completeArray){

            //THE ARRAY IS SHOWN CORRECTLY
            var_dump($completeArray);

            if(isset($_POST["registroUsuario"])){

                if(preg_match('/^[a-zA-ZñÑáéíóúÁÉÍÓÚ ]+$/', $_POST["registroUsuario"]) &&
                   preg_match('/^([0-2][0-9]|3[0-1])(\/|-)(0[1-9]|1[0-2])\2(\d{4})$/', $_POST["registroCalendario"]) &&
                   preg_match('/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/', $_POST["registroEmail"]) &&
                   preg_match('/^(?:\D*\d){2,4}\D*$/', $_POST["registroDireccion"]) &&
                   preg_match('/^[0-9]{7,12}$/', $_POST["registroTelefono"])) {

                 //HERE I WANT TO MANIPULATE EVERYTHING, BUT I CAN NOT SINCE THEY ARE NOT ARRIVING THE POST

    }

And here is the file aux.php:

if(isset($_POST['completeArray'])){

include ('purchases.controller.php');

$completeArray = json_decode($_POST['completeArray'], true);

$newPurchase = new Purchase();
$newPurchase -> ctrCash($completeArray);

}

标签: php

解决方案


推荐阅读