[Seaside] Collecting form input
Philippe Marschall
philippe.marschall at gmail.com
Mon Oct 6 18:55:31 UTC 2008
2008/10/4, Sebastian Nozzi <sebnozzi at googlemail.com>:
> Hello all,
>
> when trying to collect the values from a form, I run into a problem.
>
> Let's suppose I write a form to add a new user (user name), together
> with an user-type.
>
> I was trying to do something like this:
>
> | newName newType |
> html
> form: [html textInput value: 'type name here';
> callback: [:name | newName := name].
> html select list: userTypes;
> callback: [:userType | newType := userType];
> labels: [:userType | userType asString].
> html submitButton
> callback: [self addUserNamed: newName withType:
> newType];
> value: 'Add New User']
>
> But it didn't work. Inside of the callback-block of the submit-button,
> both variables were nil.
> I searched a little in Internet and the cause seems that when the
> block is created, it binds to the value of both variables, which at
> that time WERE nil.
>
> Is this correct? I think I read that the new Squeak versions will
> correct this "problem"? (something like a new block-compiler...)
>
> Anyway, I reverted to following solution:
> (which works)
>
> | params |
>
> params := Dictionary new.
> html
> form: [html textInput value: 'type name here';
> callback: [:name | params at: #name put: name].
> html select list: userTypes;
> callback: [:userType | params at: #type put:
> userType];
> labels: [:userType | userType asString].
> html submitButton
> callback: [self addUserNamed: (params at:#name)
> withType: (params at:#type)];
> value: 'Add New User']
>
> Did I do the right thing? Or is there a better way?
You could also use ValueHolders but that gets quite ugly. I'd use
instance variables and split it up.
Cheers
Philippe
More information about the seaside
mailing list