CGI-QuickForm

 view release on metacpan or  search on metacpan

eg/example4  view on Meta::CPAN

                    $field = &render_field( $field, $html ) ;
                }
                my $align    = qq{ align="$FIELD[$i]->{-DB_ALIGN}"} ;
                my $valign   = qq{ valign="$FIELD[$i]->{-DB_VALIGN}"} ;
                my $currency = $FIELD[$i]->{-DB_PREFIX} ;
                if( not $field ) {
                    $currency = '' ;
                    $field = ' ' ;
                }
                print "<td$align>$currency$field</td>" ;
            }
            print "</tr>" ;
        }
        print '</table>' ;
        print p( colour( "GREEN", "No matches found" ) ) unless $matches ;
        $sth->finish() ;
    } ;
    if( $@ ) { 
        print '</table>' . &fail_form( "$@ <p>Executed:<br />$stmt" .
        "<p>(My version of CSV doesn't support WHERE; my version of XBase " .
        "doesn't support LIKE.)" ) ;
    }
    else {
        print '</table>' ;
    }
    my $s = $matches == 1 ? '' : 's' ;
    print p( "$matches record$s\&nbsp;\&nbsp;" . 
             qq{<a href="$URL?$ACTION=$ADD">$ADD</a> } .
             qq{<a href="$URL?$ACTION=$FIND">$FIND</a> } .
             qq{<a href="$URL?$ACTION=$LIST">$LIST</a>} 
           ), hr, end_html ;
}


sub insert_record {

    my $stmt = "INSERT INTO $TABLE (" ; 
    {
        local $^W = 0 ;
        # Some are bound to be undefined.
        $stmt .= join ", ", map { $_->{-DB_NAME} } @FIELD ;
    }
    chop $stmt ; chop $stmt ;
    $stmt .= " ) VALUES ( " ;
    foreach my $fieldref ( @FIELD ) {
        next if $fieldref->{-TYPE} and 
                ( $fieldref->{-TYPE} eq 'hidden' or 
                  $fieldref->{-TYPE} eq 'submit' ) ;
        my $value = param( $fieldref->{-LABEL} ) ;
        $value =~ s/\n\r/ /go ;
        my $quote = $fieldref->{-DB_QUOTE} ? "'" : '' ;
        $stmt .= "$quote$value$quote, " ;
    }
    substr( $stmt, -2, 2 ) = " )" ;

    &execute_sql( $stmt,  
                  p( colour( "BLUE", "Record $KEYFIELDVAL added successfully" ) ) ) ;
}


sub update_record {

    my $stmt = "UPDATE $TABLE SET" ;
    foreach my $fieldref ( @FIELD ) {
        next if $fieldref->{-TYPE} and 
                ( $fieldref->{-TYPE} eq 'hidden' or 
                  $fieldref->{-TYPE} eq 'submit' ) ;
        my $value = param( $fieldref->{-LABEL} ) ;
        $value =~ s/\n\r/ /go ;
        my $quote = $fieldref->{-DB_QUOTE} ? "'" : '' ;
        $stmt .= " $fieldref->{-DB_NAME} = $quote$value$quote, " ; 
    }
    chop $stmt ; chop $stmt ;
    $stmt .= " WHERE $KEYFIELD = '" . param( 'OriginalKEYFIELD' ) . "'" ;
    
    &execute_sql( $stmt,
                  p( colour( "BLUE", "Record $KEYFIELDVAL updated successfully" ) ) ) ;
}


sub retrieve_record {

    my $stmt = "SELECT " ;
    {
        local $^W = 0 ;
        # Some are bound to be undefined.
        $stmt .= join ", ", map { $_->{-DB_NAME} } @FIELD ;
    } 
    chop $stmt ; chop $stmt ;
    $stmt .= " FROM $TABLE WHERE $KEYFIELD = '" .
               param( &fieldname2label( $KEYFIELD ) ) . "'" ;
    my $result = '' ; # Avoids warnings.
    $result = p( "Executed:<br />", colour( 'DARKBLUE', $stmt ) ) if $SHOW_SQL ;

    my @field ;
    eval {
        my $sth = $Dbh->prepare( $stmt ) ;
        $sth->execute() ;
        @field = $sth->fetchrow_array ; 
    } ;
    if( $@ ) {
        $result .= &fail_form( "$@ <p>Executed:<br />$stmt" ) ; 
    }
    else {
        foreach my $label ( &get_labels ) {
            param( $label, shift @field ) ;
        }
    }

    $result ;
}


sub get_where {

    my $where  = '' ;
    my $excess = '' ;

    my $i = -1 ;
    foreach my $fieldref ( @FIELD ) {
        $i++ ;



( run in 0.843 second using v1.01-cache-2.11-cpan-e1769b4cff6 )