4

I have designed one sign-up form,in this form after getting all necessary values I will click submit button.

And while clicking that submit button I want to call one function and I want to pass the arguments to that function.

I have written code for this purpose,but the function is called first before getting the details.(i.e)after getting the details in sign-up form I need to pass these values to one function and I need to validate those values.

But what happened was,before getting the details the function get called.

brian d foy
  • 129,424
  • 31
  • 207
  • 592
kiruthika
  • 2,155
  • 7
  • 26
  • 33

3 Answers3

3

Carlos's suggestion is one way. Another is to put a command callback on the button that reads the values out of the form and calls your function, perhaps like this.

$button->configure(-command => sub { yourFunc($var1, $var2); });

I'm assuming you've bound the fields of the form to the variables $var1 and $var2 here; modify to fit your own situation of course.

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
3

You have a number of options when specifying a code ref and arguments to a bind to a widget:

$w->configure( -command => [ \&subname,   @args ... ]             );
$w->configure( -command => [ sub { ... }, @args ... ]             );
$w->configure( -command => [ 'methodname', $invocant, @args ... ] );
$w->configure( -command => [ $invocant, 'methodname', @args ... ] );

See the Tk::callbacks POD for more info.

daotoad
  • 26,689
  • 7
  • 59
  • 100
0

Sounds like a vwait problem. Check in the Perl/Tk documentation for:

$widget->waitVariable(varRef)

In this way you are sure your code is only executed when the wait variable is modified (that's when you click the "submit" button)

Hope it helps.

Carlos Tasada
  • 4,438
  • 1
  • 23
  • 26