0
votes


I'm using CakePHP 2.3.1.

I need to know if there's the possibility to fill a $variable in a form field. and if (exists) how should I do it?

As you can see in my event_repeat() function.

        function repeat($id = null) {
            if (!$id) {
                    $this->Session->setFlash(__('Prenotazione non trovata'));
                    $this->redirect(array('action' => 'view', $this->data['Event']['id']));
            }

            //this is the variable I need
            $repeat = $this->data['Event']['repeat'];
            $i = 1;
            do {
                 //code

            } while ($repeat > $i);
        }

the $repeat variable, is the number of repeats the user wants, and I want it to be set by an input form as a positive integer value.

How can I make an input field refer to a variable inside the controller, instead of a database field?

1
what do you mean? set a default value of a form field? - Barry Chapman
no, I need that the input field refers directly to that variable in controller, which is not a database field. form example: $this->Form->input('repeat', array('label' => 'How many times you wish to repeat?')); - Stefano Minin

1 Answers

1
votes

In your view:

print $this->Form->input('repeat', array('label' => 'How many times you wish to repeat?', 'name' => 'data[repeats]'));

And in your controller:

$repeats = $this->data['repeats'];