Open gnat42 opened 8 years ago
So the issue is not about data_class
but the exception you get when not calling bind
?
Yeah I guess so.
Not sure what could (or should) be done in case you don't call this essential method.
I'm facing the same problem, although I do call $flow->bind($data) with an array, but the data disappears, the array stays empty. With standard Symfony Forms binding to an array is possible: http://symfony.com/doc/current/form/without_class.html
@hnesk, what happens if you do $data = new \stdClass()
instead of $data = array()
initially?
Yes, it kind of works this way
$data = (object)array(
'enrol' => array(
'email' => 'test@test.de'
),
'debit' => array(),
'address' => array(),
'message' => array(),
);
$this->flow->bind($data);
The object properties have to be set, else I get a symfony error from the property access component:
Neither the property "enrol" nor one of the methods "getEnrol()", "enrol()", "isEnrol()", "hasEnrol()", "__get()" exist and have public access in class "stdClass".
That's the same error message that I would get in standard symfony forms when I use a stdClass object as $data. It's just that symfony allows me to go freestyle with arrays, when I have to ;)
So I am here in 2019. Is there a solution for this? I'm on symfony 4 and I call the bind with an empty array but then the validations and the data for each steps are gone. Any idea?
Same problem here, can't get the data back at the end of the form since it's not mapped to a data_class
.
Did you find a solution, @andreknieriem ?
@johndoudou yes, but I don't know if its a good way. I create an empty stdClass object with all fields for all steps and null values. This works pretty well. The flow-config is an option by myself, but I hope I can give a hint.
public function generateFormObject($flow)
{
$formData = new \stdClass();
foreach($flow->config['steps'] as $step) {
foreach($step['fields'] as $key=>$field) {
$formData->$key = null;
}
}
return $formData;
}
Hello,
I was playing around with a form flow. I ran into some odd issues because at one point I wanted to change my forms to not have a data_class. Doing so resulted in all sorts of what I consider 'odd' bugs.
Because none of the forms had a data_class I didn't see any reason to call
This results in odd errors about expecting an INT when calling getStepNumber or something like that. It seems to me that really there should be some kind of 'initialized' flag that bind() sets to true. Then other functions throw a sensible exception when not properly initialized and inform the user/developer to call bind.
Thoughts?