Phalcon\Tag::resetInput() is not work #12099

Closed
Studentsov opened this Issue Aug 5, 2016 · 14 comments

Projects

None yet

4 participants

@Studentsov
Contributor
Studentsov commented Aug 5, 2016 edited

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 Studentsov changed the title from Phalcon\Tag::resetInput() is not work in Phalcon 3.0.0 to Phalcon\Tag::resetInput() is not work Aug 5, 2016
@sergeyklay sergeyklay modified the milestone: 3.0.x, 3.0.2 Aug 10, 2016
@sergeyklay
Collaborator
sergeyklay commented Oct 1, 2016 edited

@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 sergeyklay added Not a bug and removed Bug - Medium labels Oct 1, 2016
@Studentsov
Contributor
Studentsov commented Oct 1, 2016 edited

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

@Jurigag
Contributor
Jurigag commented Oct 1, 2016 edited

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

@sergeyklay
Collaborator

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

@niden
Collaborator
niden commented Oct 1, 2016

@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
@Jurigag
Contributor
Jurigag commented Oct 1, 2016 edited

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

@Studentsov
Contributor

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

@sergeyklay
Collaborator

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

@sergeyklay sergeyklay added Bug - Medium and removed Not a bug labels Oct 1, 2016
@sergeyklay
Collaborator

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

@sergeyklay sergeyklay self-assigned this Oct 2, 2016
@sergeyklay
Collaborator

Fixed in 3.0.x branch.
Could you please check 3.0.x branch?

git clone git@github.com:phalcon/cphalcon.git
cd cphalcon
git checkout 3.0.x

zephir fullclean
zephir build
@sergeyklay sergeyklay closed this Oct 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment