How do I set a computed value in a form in a view that I can read after form submission?
Either I have the concept wrong, the function wrong or something else.
I've got a view with form input
some of wording of the form input is based on a random value, and I need to know the random value that was set after the form is submitted.
I want to set the random value in the form
I tried
$myrand = rand(1,9);
with both of these below: (not sure if this the correct way or which one is correct).
echo $this->Form->Hidden('MyResult', $myrand);
echo $this->Form->AddHidden('MyResult',$myrand);
then I want to read the result in an function in the plugin
e.g.
$Sender->EventArguments['User']['MyResult'];
the dump of " $Sender->EventArguments['User']['MyResult'] " is always string[0] ""
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Comments
don't know if it is the best way to do it - but this how I solved it.
echo $this->Form->Hidden('MyResult',array('value' => "$myrand"));
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
You usually want to call
AddHidden()
in your plugin, not the view. This queues up a hidden value which will be rendered byGdn_Form->Open()
.Your call to
Gdn_Form->Hidden(...)
is perfectly fine though.Bonus advice:
mt_rand()
is supposedly a better random number generator thanrand()
. The php docs even go so far as to callrand()
dubious (gasp).thanks for the explanation. Todd.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.