jwlarson3rd has asked for the wisdom of the Perl Monks concerning the following question:

I am building a image gallrey. I can display all of the pictures in a user gallery and I have next prev exit buttons on a single image display. I need to stop the the prev and next buttons from when I reach the beginning or end of pictures to display. I can get first and last record id for a individual user but when I wrap a if statement around the form if doesn't work. any ideas on how to stop a submit button from working when I don't want it to work tied to some condition john larson

Replies are listed 'Best First'.
Re: conditional submit buttons
by eric256 (Parson) on Dec 12, 2003 at 02:02 UTC

    Well you could just not print out the button itself when you don't want them to use it.

    If thats what you mean you tried, perhaps you could give us an example of the the code so we could help you out.


    ___________
    Eric Hodges
Re: conditional submit buttons
by Zaxo (Archbishop) on Dec 12, 2003 at 02:03 UTC

    To help, we'll have to see how you have things organized. Please show your code.

    After Compline,
    Zaxo

      if($firstrec <= $lastrec) { print $q->start_form(-name=>'displaynext',-method=>'POST',-action=>'ne +xt.cgi'); print "<input type=hidden name=i value='$id'>"; print "<input type=hidden name=u value='$username'>"; print $q->submit(-name=>'next',-value=>'next'); print $q->end_form(); } print $q->start_form(-name=>'display prev',-method=>'POST',-action=>'p +rev.cgi'); print "<input type=hidden name=i value='$id'>"; print "<input type=hidden name=u value='$username'>"; print $q->submit(-name=>'prev',-value=>'prev'); print $q->end_form();

      the next button is the same as prev button
      $firstrec is the first record in a user group
      $lastrec is the last record in a user group
      when I reach the $lastrec I want to stop the next button from working and when i reach $firstrec i want the prev button to stop working.

      john larson

      20031212 Edit by Corion: Added formatting, fixed CODE tags

        hmmm.. what is the value of the image currently being displayed? Is $id a visitor id or the current image id?

        assuming $id, $firstrec, & $lastrec are numerical codes representing current image, first image, and last image, and your image codes are sorted numerically.. maybe you're looking for something like this?

        if ( $id < $lastrec ){ print $q->start_form(-name=>'displaynext',-method=>'POST',-action=>' +next.cgi'); print "<input type=hidden name=i value='$id'>"; print "<input type=hidden name=u value='$username'>"; print $q->submit(-name=>'next',-value=>'next'); print $q->end_form(); } if ( $id > $firstrec ){ print $q->start_form(-name=>'display prev',-method=>'POST',-action=> +'prev.cgi'); print "<input type=hidden name=i value='$id'>"; print "<input type=hidden name=u value='$username'>"; print $q->submit(-name=>'prev',-value=>'prev'); print $q->end_form(); }

        cheers,

        J

Re: conditional submit buttons
by Roger (Parson) on Dec 12, 2003 at 02:13 UTC
    You could have a look at a simple CGI slide-show example I wrote earlier - 312442, where it cycles through the list instead of stopping at the first and last images.

    And you could display greyed out button image instead of generating a submit button when you reach the start and end of the sequence.

Re: conditional submit buttons
by Anonymous Monk on Dec 12, 2003 at 13:40 UTC
    You could always disable the button at a certain point:
    if (End...) { $button->configure(-state => 'disable') }