cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

Phalcon\Tag::resetInput() is not work

Open Studentsov opened this issue 10 years ago • 14 comments

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 avatar Aug 05 '16 21:08 Studentsov

@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.

sergeyklay avatar Oct 01 '16 17:10 sergeyklay

Implementation of the Phalcon\Forms\Form::clear depends on the state of the Phalcon\Tag

Studentsov avatar Oct 01 '16 18:10 Studentsov

Where - https://github.com/phalcon/cphalcon/blob/master/phalcon/forms/form.zep#L663

Jurigag avatar Oct 01 '16 18:10 Jurigag

https://github.com/phalcon/cphalcon/blob/master/phalcon/forms/element.zep#L507

Studentsov avatar Oct 01 '16 18:10 Studentsov

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

Jurigag avatar Oct 01 '16 18:10 Jurigag

@Studentsov But Phalcon\Forms\Element::clear not doing anything with $_POST

sergeyklay avatar Oct 01 '16 18:10 sergeyklay

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

Studentsov avatar Oct 01 '16 18:10 Studentsov

https://github.com/phalcon/cphalcon/blob/master/phalcon/tag.zep#L333 oh okay, here you right.

Jurigag avatar Oct 01 '16 18:10 Jurigag

@sergeyklay and I had a discussion and this is how this must work:

  • $_POST or $_GET must not be manipulated by the framework
  • Phalcon\Tag::resetInput() must clear only the input of the Phalcon\Tag object and not the $_POST
  • Phalcon\Forms\Element::clear() must clear only the form elements and not the $_POST

niden avatar Oct 01 '16 18:10 niden

So also this 333 line from tag.zep can't get value form $_POST. Or Form shouldn't use Tag::getValue

Jurigag avatar Oct 01 '16 18:10 Jurigag

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 avatar Oct 01 '16 18:10 Studentsov

@Studentsov I'll implement clearing forms without clearing $_POST

sergeyklay avatar Oct 01 '16 18:10 sergeyklay

@Studentsov Could you please take a look at #12280? In general this is what you need. Right?

sergeyklay avatar Oct 01 '16 19:10 sergeyklay

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

sergeyklay avatar Oct 02 '16 00:10 sergeyklay