Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions /

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba

Did something change in form action execution ?


Go to End
Reply


4 Posts   2179 Views

Avatar
walec51

Community Member, 16 Posts

5 July 2009 at 12:58am

Hi,

I see in the wiki that action methods looked like this:

function doform($data, $form) {
// ... you already made this ...
}

but in 2.3.2 they seam to be executed like this:

function doform($httpRequest) {
// ... you already made this ...
}

is this the new default behavior or em I missing something?

Avatar
Willr

Forum Moderator, 5521 Posts

5 July 2009 at 11:00am

No this hasn't changed. You should still use doForm($data, $form) for 2.3 sites. If some has updated the documentation with that change then it is wrong. A major API change like this would not be part of a point release like 2.3.2.

Avatar
walec51

Community Member, 16 Posts

5 July 2009 at 12:45pm

Edited: 05/07/2009 12:45pm

Hmmm then I don't understand something.
My action methods seam to be called with only the HttpRequest argument.
I look in the the Controller.php to check this and I also see:

function handleAction($request) {

//...

// run & init are manually disabled, because they create infinite loops and other dodgy situations
if($this->checkAccessAction($this->action) && !in_array(strtolower($this->action), array('run', 'init'))) {
if($this->hasMethod($methodName)) {
$result = $this->$methodName($re;'quest);
//...

shouldn't the line

$result = $this->$methodName($request);

look somewhat like this

$result = $this->$methodName($data, $form);

or em I looking in the wrong place ?

Avatar
walec51

Community Member, 16 Posts

7 July 2009 at 11:21am

Just found what caused my problem :)

I don't know why but I added my doform method to the $allowed_actions variable. Sorry for the false alarm.

Meanwhile while doing my first bigger form I stumbled for a few hours with another mistake of mine. I didn't make the form name the same as the name of the controller method that generates it. Could you add a remark on the wiki about this like:

function Form() {
return new Form($this,
// the name of the form MUST be the same
// as the name of the method that generates it
"Form",
new FieldSet(
//...

otherwise the $form argument won't get initialized properly in the doform method.

http://doc.silverstripe.org/doku.php?id=recipes:forms