Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Clear form does not work #15956

Closed
bakos opened this issue May 11, 2022 · 4 comments · Fixed by #16191
Closed

[BUG]: Clear form does not work #15956

bakos opened this issue May 11, 2022 · 4 comments · Fixed by #16191
Assignees
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: high High

Comments

@bakos
Copy link

bakos commented May 11, 2022

Describe the bug

Clear is not working on form elements values. (https://docs.phalcon.io/5.0/pl-pl/api/phalcon_forms : Clears element to its default value)

To Reproduce
Steps to reproduce the behavior:

$textField = new Text('textField', [
            'placeholder' => 'Text field to clear after submit',

        ]);
        $textField->clear();
        $this->add($textField);

This should clear element to its default value

Provide minimal script to reproduce the issue

Form:

class ExampleForm extends Form
{
    public function initialize($entity = null, $options = null)
    {
        $textField = new Text('textField', [
            'placeholder' => 'Text field to clear',
        ]);
        $textField->clear();
        $this->add($textField);
    }
}

Action in contoller

        $form = new ExampleForm();
        if ($this->request->isPost()) {
            if (!$form->isValid($_POST)) {
                $form->clear();
                $this->view->error = "form is cleared";
            }
        }
        $this->view->form = $form;

Template view

<form id="form" action="/index/index" method="post">
    This field should be cleared after submit
    <?php
    foreach ($form as $element)
    {
        echo $element;
    }
    ?>
</form>

Expected behavior

Fields values should be cleared. It works in phalcon 3.x and 4.x.

Details

  • Phalcon version: 5.0.0beta3
  • PHP Version: 7.4.28

Additional context

I found commit related to the problem:

9992bb2

@bakos bakos added bug A bug report status: unverified Unverified labels May 11, 2022
@bakos
Copy link
Author

bakos commented May 11, 2022

Ater few more tests if you change order and add field first and then you try to clear it then it couse Segmentation fault (11) - only in 5.x version. 3.x and 4.x order is not a problem

$textField = new Text('textField', [
     'placeholder' => 'Text field to clear after submit',
]);
$this->add($textField);
$textField->clear();

@Deathamns
Copy link
Contributor

I think I'm facing the same problem. Win10, PHP 8.1.7, Phalcon v5.0.0RC2.
The script below simply freezes (with at least one element and Form->clear()).
A "windows problem reporting" process starts running at 30% CPU, which if I kill the script terminates as well.

<?php

class TestForm extends \Phalcon\Forms\Form {
	public function initialize() {
		$this->add(new \Phalcon\Forms\Element\Text('test'));
		// freezes with clear
		$this->clear();
	}
}

new TestForm;

@alimo2
Copy link

alimo2 commented Oct 30, 2022

When i use clear() on element, it goes to infinite loop!

Details:
Phalcon version: 5.0.0RC3
PHP Version: 8.1.9

@niden niden self-assigned this Nov 1, 2022
@niden niden added status: high High 5.0 The issues we want to solve in the 5.0 release and removed status: unverified Unverified labels Nov 1, 2022
@niden niden added this to Phalcon v5 Nov 1, 2022
@niden niden moved this to Backlog in Phalcon v5 Nov 1, 2022
@niden niden moved this from Backlog to In Progress in Phalcon v5 Nov 1, 2022
@niden niden mentioned this issue Nov 1, 2022
5 tasks
@niden niden linked a pull request Nov 1, 2022 that will close this issue
5 tasks
@niden
Copy link
Member

niden commented Nov 1, 2022

Resolved in #16191

Thank you @bakos @Deathamns @alimo2

@niden niden closed this as completed Nov 1, 2022
Repository owner moved this from In Progress to Implemented in Phalcon v5 Nov 1, 2022
@niden niden moved this from Implemented to Released in Phalcon v5 Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: high High
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants