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

[2.0.x] Setting form element name to "value" produces BadMethodCallException during render #10398

Closed
cinu opened this issue May 25, 2015 · 6 comments
Assignees
Labels
bug A bug report status: medium Medium

Comments

@cinu
Copy link

cinu commented May 25, 2015

Setting form element name to "value" produces BadMethodCallException (Wrong number of parameters) during render.

Reproduction code:

<?php
$di = new \Phalcon\DI\FactoryDefault();

use Phalcon\Forms\Form;
use Phalcon\Forms\Element\Text;

class FormTest extends Form
{
    public function initialize()
    {
        $this->add(new Text("value"));
        $this->add(new Text("value2"));
    }
}

$f=new FormTest();
echo $f->render('value2'); // works
echo $f->render('value'); // exception

/*
output:

<input type="text" id="value2" name="value2" />PHP Fatal error:  Uncaught exception 'BadMethodCallException' with message 'Wrong number of parameters' in /.../test.php:18
Stack trace:
#0 [internal function]: Phalcon\Forms\Form->getValue()
#1 [internal function]: Phalcon\Forms\Form->getValue('value')
#2 [internal function]: Phalcon\Forms\Element->getValue()
#3 [internal function]: Phalcon\Forms\Element->prepareAttributes(NULL)
#4 [internal function]: Phalcon\Forms\Element\Text->render(NULL)
#5 /.../test.php(18): Phalcon\Forms\Form->render('value')
#6 {main}
  thrown in /.../test.php on line 18

PHP: 5.6.7-1 (debian)
Phalcon: 2.0.1

@jkmf
Copy link

jkmf commented May 28, 2015

I just like to add that other forbidden form element names are:
'label', 'messages', 'messagesfor', 'elements'
and probably lot more...

@cinu cinu changed the title Setting form element name to "value" produces BadMethodCallException during render [2.0.x] Setting form element name to "value" produces BadMethodCallException during render May 28, 2015
@berliner
Copy link

Elements with name "value" are getting rendered without problems when passing a model into the form constructor, e.g.:
$form = new Form(new MyModel());

Tested with phalcon 2.0.1

@andresgutierrez
Copy link
Contributor

It checks if the form has a 'getter' to obtain the value of the element, as the form value has a method called getValue, it tries to use it to obtain the value

@mzf
Copy link

mzf commented Jul 16, 2016

+1
If column named as value then Form\Element throw BadMethodCallException("Wrong number of parameters") when call render

@sergeyklay
Copy link
Contributor

I'll try to sort out

@sergeyklay
Copy link
Contributor

Fixed in the 2.1.x branch.

@niden niden added bug A bug report status: medium Medium and removed Bug - Medium labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: medium Medium
Projects
None yet
Development

No branches or pull requests

7 participants