# Process form if submitted; otherwise display it if ($co->param("submit")){ process_form ( ); }else{ display_form ( ); } sub process_form{ if ( validate_form()){ print $co->start_form( -method=>'POST', -action=>"http://mywebserver/cgi-bin/script2.cgi", ), $co->end_form(), $co->end_html; END{} } } sub validate_form{ my $searchfield = $co->param("searchfield"); my $error_message = ""; $error_message .= "Please enter a value into the searchfield
" if ( $searchfield eq "" ); if ($error_message){ # Errors with the form - redisplay it and return failure display_form ( $error_message, $searchfield, ); return 0; }else{ # Form OK - return success return 1; } } #### sub display_form{ my $error_message = shift; my $searchfield = shift; print $co->start_form( -method=>'POST', -action=>"http://mywebserver/cgi-bin/script1.cgi", ), . . . #loads of extra stuff here . . $co->hidden( -name=>'submit', -value=> "Submit"), ), $co->end_form(),