I’m a coder. Welcome to my blog. Here are some of the records on my job.
Home
Categories
PHP: send $ _POST data to my class?
I’m trying to send my $_POST data to a class of mine for processing. but it doesn’t seem to matter how I send it, PHP is telling me:
Trying to get property of non-object
public function test_me_out($postdata) < if(isset($postdata->price)) < return "the price was: " . $postdata->price . " …and this was added."; > else < return "it's apparently not set. "; >>
$_POST is not an object. You should access its information using it as an array like $_POST[‘my_data’] .
Related Articles
How to transfer data to the server using ajax and PHP? $ _POST [’data’] will not work
I have an HTML form that I want to send to the server (using a PHP script) some information before it gets submitted. I’m using .ajax() jQuery function as well. Here’s my demo.html file:
PHP sends encrypted data via URL
I’m trying to send encrypted data over the url to another site (using file_get_contents(«anotherUrl.php?hash=$encryptedString»). The problem is, sometimes, the encryption contains some special characters, like +, and this causes the decryption t
Sending bundle / data to another class or screen
What am I doing wrong? I’ve looked at other questions and thought I was doing the exact same things, but since its not working for me, obviously I’m doing something wrong! I have my MainActivity.class that gets JSON data (coordinates) from a URL. Thi
PHP — Form $ _POST data table does not return the necessary information
How to send $ _POST data from the form to the function with other variables?
I’m trying to pass data from a form to another function in another file, but this function already has other variables that is coming from another function.
Send HTML data for php
Php $ _POST [’data’. $ I] increases the number `$ i`
Maybe this is a strange question. I have many button pass value with jquery. they are very similar. so i tried to combine them with number increase. index.php
Sending form data using POST to the current page and another PHP page at the same time
I have seen another person ask this question in stack overflow but I did not get any clear answer/idea from ‘his post’. I want to know whether there is a way of sending form data via POST to the current PHP page addstudio.php to verify the entered da
If you don’t validate $_SESSION[‘token’] first, it won’t work.
Thank you guys for clarifying all this for me.
yendrrek 191
Like the comments pointed out, I think there are some problems with the approach that would likely rectify your issues. Try this:
trait TokenTrait < public $token = null; function setToken() < if ($this->token === null) < $this->token = bin2hex(random_bytes(64)); > return $this->token; > > class Token < use TokenTrait; public function __construct() < $this->setToken(); > > class ContactForm < use TokenTrait; public $name; public $name_error; public $token; public function __construct() < $this->name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING) ?: null; $this->name_error = filter_input(INPUT_POST, 'name_error', FILTER_SANITIZE_STRING) ?: null; $this->token = filter_input(INPUT_POST, 'token', FILTER_UNSAFE_RAW) ?: null; > public function validateContactForm() < if (!empty($this->token)) < // Validate the token. No need to pull from post since you did that in construct if (hash_equals($_SESSION['token'], $this->token)) < // If the token is valid proceed. if (getenv('REQUEST_METHOD') == 'POST') < if (filter_input(INPUT_POST, 'submit') !== null) < // Rest of the validating code which works if I remove above token // or if I validate $_SESSION['token'] against itself. >> > > > >
Granted, I can’t see where all the pieces, such as your TokenTrait, fit into your larger Web App, but I’d question it’s usefulness in the ContactForm class.