php - 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);
}
解决方案
推荐阅读
- pine-script - Pine Script中的数组是否有任何解决方法
- tensorflow - Tensorflow:在除法之前添加小数字以实现数值稳定性
- html - 有没有办法对齐 HTML 表格中的列?
- c# - "," 附近的语法错误正在更新数据库行
- python - 为什么我应该“谨慎使用内联注释”?
- vb.net - 在 Windows 窗体中使用声明的对象作为数组创建句柄
- javascript - 捕获父文档中多个子 iFrame 的 keydown 事件?
- c# - 如何在 inkcanvas 上绘制可修改的折线
- php - 如何使用 Stripe webhook / 端点获取客户电子邮件
- java - 搜索 arrayLists 的映射树