Phalcon\Tag::resetInput() is not work
Code:
$_POST = ['a' => '1', 'b' => '2'];
\Phalcon\Tag::resetInput();
var_dump($_POST);
output:
array(2) { ["a"]=> string(1) "1" ["b"]=> string(1) "2" }
Phalcon 3.0.0 OS Windows 10, PHP 7.0.8 x64 OS CentOS 7, PHP 7.0.9 x64
This problem breaks clean forms. I found an old message: http://stackoverflow.com/questions/37365130/how-to-clear-phalcon-form-element-values, so I think the problem is not new.
@Studentsov
Why did you decide that the Phalcon\Tag::resetInput should reset $_POST? Could you please explain a bit more?
As correctly noted @SidRoberts in #12227 the Phalcon\Tag::resetInput shouldn't reset $_POST. It should only reset parameters within the Phalcon\Tag object.
I agree that we have variances in the documentation about this method, and it was used in an unsuccessful attempt to clear $_POST.
But I'm really not sure that we need a method to do $_POST = [];
To clear the form you should use Phalcon\Forms\Form::clear. It clears every element in the form to its default value. I'll check Phalcon\Forms\Form::clear ASAP, but anyway this is a different issue, not related with cleaning $_POST through Phalcon\Tag::resetInput.
Implementation of the Phalcon\Forms\Form::clear depends on the state of the Phalcon\Tag
Where - https://github.com/phalcon/cphalcon/blob/master/phalcon/forms/form.zep#L663
https://github.com/phalcon/cphalcon/blob/master/phalcon/forms/element.zep#L507
So what ? Still it shouldn't reset $_POST. The values in form are not got from $_POST for displaying.
Also this method isn't cleaning $_POST https://github.com/phalcon/cphalcon/blob/master/phalcon/tag.zep#L258
@Studentsov But Phalcon\Forms\Element::clear not doing anything with $_POST
https://github.com/phalcon/cphalcon/blob/master/phalcon/forms/element.zep#L433 https://github.com/phalcon/cphalcon/blob/master/phalcon/tag.zep#L258 https://github.com/phalcon/cphalcon/blob/master/phalcon/tag.zep#L321 just try to clean form
https://github.com/phalcon/cphalcon/blob/master/phalcon/tag.zep#L333 oh okay, here you right.
@sergeyklay and I had a discussion and this is how this must work:
$_POSTor$_GETmust not be manipulated by the frameworkPhalcon\Tag::resetInput()must clear only the input of thePhalcon\Tagobject and not the$_POSTPhalcon\Forms\Element::clear()must clear only the form elements and not the$_POST
So also this 333 line from tag.zep can't get value form $_POST. Or Form shouldn't use Tag::getValue
I'm glad such a rapid discussion of architecture, but I just have to clear the form :D I think you can change the title of issue
@Studentsov I'll implement clearing forms without clearing $_POST
@Studentsov Could you please take a look at #12280? In general this is what you need. Right?
Fixed in 3.0.x branch.
Could you please check 3.0.x branch?
git clone [email protected]:phalcon/cphalcon.git
cd cphalcon
git checkout 3.0.x
zephir fullclean
zephir build