From 3223b9f1872063b0c1ba864880449e40c68d590d Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Tue, 6 Sep 2005 03:41:20 +0000 Subject: Bug 304745: Move GetFieldID() out of globals.pl - Patch by Frédéric Buclin r=wicked a=justdave MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bugzilla/Field.pm | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'Bugzilla/Field.pm') diff --git a/Bugzilla/Field.pm b/Bugzilla/Field.pm index 26265ac3d..09c4731ac 100644 --- a/Bugzilla/Field.pm +++ b/Bugzilla/Field.pm @@ -20,7 +20,8 @@ package Bugzilla::Field; use strict; use base qw(Exporter); -@Bugzilla::Field::EXPORT = qw(check_form_field check_form_field_defined); +@Bugzilla::Field::EXPORT = qw(check_form_field check_form_field_defined + get_field_id); use Bugzilla::Util; use Bugzilla::Error; @@ -52,6 +53,22 @@ sub check_form_field_defined { } } +sub get_field_id { + my ($name) = @_; + my $dbh = Bugzilla->dbh; + + trick_taint($name); + my $id = $dbh->selectrow_array('SELECT fieldid FROM fielddefs + WHERE name = ?', undef, $name); + + ThrowCodeError('invalid_field_name', {field => $name}) unless $id; + return $id +} + +1; + +__END__ + =head1 NAME Bugzilla::Field - Useful routines for fields manipulation @@ -63,7 +80,7 @@ Bugzilla::Field - Useful routines for fields manipulation # Validation Routines check_form_field($cgi, $fieldname, \@legal_values); check_form_field_defined($cgi, $fieldname); - + $fieldid = get_field_id($fieldname); =head1 DESCRIPTION @@ -101,4 +118,14 @@ Params: $cgi - a CGI object Returns: nothing +=item C + +Description: Returns the ID of the specified field name and throws + an error if this field does not exist. + +Params: $fieldname - a field name + +Returns: the corresponding field ID or an error if the field name + does not exist. + =back -- cgit v1.2.3-24-g4f1b