CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
How to get input text boxes populated

 



terrykhatri531
User

Jul 6, 2014, 9:33 AM

Post #1 of 22 (3002 views)
How to get input text boxes populated Can't Post

Hi,



I know how to populate a combo box or a drop down list box which I do as under :



Query that gets the data for the drop down box :




Code
  



$qry = "select \"EmployeeID\" AS empid, \"FirstName\"::text || ' ' ||\"LastName\"::text as name from \"Employees\"";
$qq = $db_handle->prepare($qry);
$qq->execute;
while (@row = $qq->fetchrow) {
$tt .= "<option value=$row[0]>$row[1]</option>\n";
}





And below is how I assign the values driven from database to a drop down lis box which gets populated :




Code
  

<form method=POST>
Select an employee to be updated and press FETCH:<select name=empid>$tt</select><br>

..............





Now back to the input text boxes how do I populate them, how do I assign values to them :

Here is the query that fetches data for the input text boxes but I don't know how to assign values driven from the query to the text boxes :




Code
  

# If the form has been completed, save data entered
if ($input{"go"} eq "FETCH") {
$query = "SELECT
\"LastName\" AS ln,
\"FirstName\" AS fn,
\"Title\" AS tl,
\"TitleOfCourtesy\" AS tc,
\"BirthDate\" AS bd,
\"HireDate\" AS hd,
\"Address\" As ad,
\"City\" AS ct,
\"Region\" AS rg,
\"PostalCode\" AS pc,
\"Country\" AS cy,
\"HomePhone\" AS hp,
\"Extension\" AS xt,
\"Notes\" AS nt,
\"ReportsTo\" AS rt
FROM
\"Employees\"
WHERE
\"EmployeeID\"="." \'$input{empid}\'";

$ins = $db_handle->prepare($query);
$ins->execute;
while (@row = $ins->fetchrow) {
$ln .= "<input value=$row[0]></input>\n";
$fn .= "<input value=$row[1]></input>\n";
$tl .= "<input value=$row[2]></input>\n";
$tc .= "<input value=$row[3]></input>\n";
$bd .= "<input value=$row[4]></input>\n";
$hd .= "<input value=$row[5]></input>\n";
$ad .= "<input value=$row[6]></input>\n";
$ct .= "<input value=$row[7]></input>\n";
$rg .= "<input value=$row[8]></input>\n";
$pc .= "<input value=$row[9]></input>\n";
$cy .= "<input value=$row[10]></input>\n";
$hp .= "<input value=$row[11]></input>\n";
$xt .= "<input value=$row[12]></input>\n";
$nt .= "<input value=$row[13]></input>\n";
$rt .= "<input value=$row[14]></input>\n";
}





Here is the form data I want to fill in with above values driven from the database :




Code
  

<div class="container">
<form method=POST>
Select an employee to be updated and press FETCH:<select name=empid>$tt</select><br>
<input type=submit name=go value=FETCH>
Last Name :<input name=lastname><br>
First Name :<input name=firstname><br>
Title :<input name=title><br>
Title Of Courtesy :<input name=toc><br>
Birth Date :<input name=dob><br>
Hire Date :<input name=doh><br>
Address :<input name=address><br>
City :<input name=city><br>
Region :<input name=region><br>
Postal Code :<input name=pcode><br>
Country :<input name=country><br>
Home Phone :<input name=homephone><br>
Extension :<input name=ext><br>
Notes :<input name=notes><br>
Reports To :<select name=repto>$hh</select><br>
<input type=submit name=go value=UPDATE>
</div>
</form><hr>





Many thanks in advance for your kind help !!

Please note that I will post it on perlmonks as well.



Rgds

Terry


Laurent_R
Veteran / Moderator

Jul 6, 2014, 11:34 PM

Post #2 of 22 (2983 views)
Re: [terrykhatri531] How to get input text boxes populated [In reply to] Can't Post

Not sure about your question, but just one comment that may make your coding life easier. Rather than escaping the quotes within your query, you might use a differernt quoting mecanism. For example something like this:

Code
$query = 'SELECT   
"LastName" AS ln,
"FirstName" AS fn,
"Title" AS tl,
"TitleOfCourtesy" AS tc,
"BirthDate" AS bd,
# ...
FROM
"Employees"
WHERE
"EmployeeID" =' . $input{empid};


or, if you want variable interpolation:


Code
$query = qq [ SELECT   
"LastName" AS ln,
"FirstName" AS fn,
"Title" AS tl,
"TitleOfCourtesy" AS tc,
"BirthDate" AS bd,
# ...
FROM
"Employees"
WHERE
"EmployeeID" = . $input{empid} ];



Zhris
Enthusiast

Jul 7, 2014, 2:18 AM

Post #3 of 22 (2980 views)
Re: [terrykhatri531] How to get input text boxes populated [In reply to] Can't Post

Hi,

Its not entirely clear what your issue is, my guess is you'll need to do the following for each field in your template:


Code
Last Name :<input name=lastname><br> 
Last Name :$ll<br>


the last name input tag was earlier assigned to $ll.

And a few other things I noted with your code:

1) I assume your database object is DBI. I can't find the statement handler method fetchrow, but there is a fetchrow_array.

2) Don't interpolate variables directly in your query otherwise you run the risk of an SQL injection attack. Bind them to the query either in the execute call or by using the bind_param method:

Code
my $query = <<'QUERY'; 
SELECT
"Lastname"
FROM
"Employees"
WHERE
"EmployeeID" = ?
QUERY

$ins = $db_handle->prepare($query);
$ins->execute($input{empid});


4) Remember to encode HTML entities where necessary. Encode the value of form fields, especially if they come from user input i.e. upon re-population after form validation fail.

5) Use HTML best practices i.e. quote tag attribute values, otherwise you'll surely run into issues later down the line:

Code
Last Name :<input name=lastname><br> 
Last Name :<input name="lastname"><br />


And finally some further advice:

1) Use a templating system such as Template::Toolkit. This allows you to separate Perl logic from HTML. Trust me, it makes life a lot easier when writing web applications. If I remember rightly from a previous post, you are already familiar with using HTML::Template.

2) Inevitably you have only shown us small portions of your code, but i'm guessing as a whole its convoluted, even basic applications start out simple, but quickly become intricate. Try to break your code up into separate functions that have specific purposes and avoid repeating code. For starters, use a hash dispatch table that calls the function that correlates with which button was pressed.

Code
my $button = $input{'go'}; 

my $dispatch =
{
'DEFAULT' => \&default,
'FETCH' => \&fetch,
'UPDATE' => \&update
};

$button = 'DEFAULT' if (not defined $button or not exists $dispatch->{$button});

$dispatch->{$button}->(input => \%input);

sub default
{
form( );
}

sub fetch
{
print 'fetching...'
}

sub update
{
print 'updating...';
}

sub form
{
print 'form...';
}


3) Consider looking into basic web application frameworks starting with the likes of Web::Simple and CGI::Application. They help you to organize your application and do the nitty bitty bits for you.

Regards,

Chris


(This post was edited by Zhris on Jul 7, 2014, 2:31 AM)


terrykhatri531
User

Jul 7, 2014, 7:49 AM

Post #4 of 22 (2968 views)
Re: [Zhris] How to get input text boxes populated [In reply to] Can't Post

Hi Chris,

Thanks for your comments, I will definitely study the Template Kit, right now I am stuck in my edit employee script, problem is its not executing a part of it which is ACTION UPDATE, and its not even giving me any errors and its not sending any update statement to the database, if you kindly look at it I am sure you will see the problem because you are so good at web stuff.

Here is the script :


Code
 
#!/usr/local/bin/perl
use strict;
use CGI;
use CGI::Carp 'fatalsToBrowser'; #remove for prod
use DBI;

# get form parameters
my $q = new CGI;
my $action = $q->param('go');
my $empid = $q->param('empid');

my $dbh = dbh(); # connect to db
$dbh->do("SET search_path to northwind") or die;

# If the confirm form was properly submitted, update the record
my $msg;
# change validation to suit
if ( ($action eq "UPDATE") && ($empid =~ /\d+/)) {

my @data=();
my @fields = qw!lastname firstname title toc dob doh address city
region pcode country homephone ext repto notes !;
for my $f (@fields){
push @data,$q->param($f) || '' ;
}
push @data,$empid;

my $sql = qq!UPDATE "Employees"
SET "LastName" = ?,
"FirstName" = ?,
"Title" = ?,
"TitleOfCourtesy" = ?,
"BirthDate" = ?,
"HireDate" = ?,
"Address" = ?,
"City" = ?,
"Region" = ?,
"PostalCode" = ?,
"Country" = ?,
"HomePhone" = ?,
"Extension" = ?,
"ReportsTo" = ?,
"Notes" = ?,
WHERE "EmployeeID" = ? !;

my $count = $dbh->do( $sql,undef,@data);
$msg = "$count Record updated - $sql, @data";
} else {
$msg = "Please complete form";
}


# get employees
my $sql = qq!SELECT "EmployeeID" AS empid,
"FirstName"::text || ' ' ||"LastName"::text AS name
FROM "Employees" !;
my $ar = $dbh->selectall_arrayref($sql);

# Make up a pulldown menu
my $options = qq!<option value="">select name</option>!;
for my $row (@$ar) {
$options .= qq!<option value="$row->[0]">$row->[1]</option>\n!;
}

# build html page
my $style = q!
body { background-color: pink ; color: #3300cc; }
.container { width: 500px; clear: both; }
.container input { width: 100%; clear: both;}
!;

# Send out the header and form
print $q->header;
print $q->start_html(-title=>'Update an employee record',
-style=>{ -code=>$style } );
print qq!<h1 style="color:3300CC">Please update an employee</h1>!;

# Fetch data
if ( $action eq "FETCH" ) {
#print qq!<h3>Please make the necessary updates to $empid ?</h3>
my $sql = 'SELECT * FROM "Employees"
WHERE "EmployeeID" = ?';
my $hr = $dbh->selectrow_hashref($sql,undef,$empid);
#my $hr = $dbh->selectrow_hashref($sql,undef,$input{empid});

print qq!<div class="container">
<form action="" method="post">
Employee ID : $hr->{'EmployeeID'}<br/>
<input type="hidden" name="EmployeeID" value="$hr->{'empid'}"/>
Last Name :<input name="lastname" value="$hr->{'LastName'}"/><br/>
First Name :<input name="firstname" value="$hr->{'FirstName'}"/><br/>
Title :<input name="title" value="$hr->{'Title'}"/><br/>
Title Of Courtesy :<input name="toc" value="$hr->{'TitleOfCourtesy'}"/><br/>
Birth Date :<input name="dob" value="$hr->{'BirthDate'}"/><br/>
Hire Date :<input name="doh" value="$hr->{'HireDate'}"/><br/>
Address :<input name="address" value="$hr->{'Address'}"/><br/>
City :<input name="city" value="$hr->{'City'}"/><br/>
Region :<input name="region" value="$hr->{'Region'}"/><br/>
PostalCode :<input name="pcode" value="$hr->{'PostalCode'}"/><br/>
Country :<input name="country" value="$hr->{'Country'}"/><br/>
Home Phone :<input name="homephone" value="$hr->{'HomePhone'}"/><br/>
Extension :<input name="ext" value="$hr->{'Extension'}"/><br/>
Reports To :<select name="repto"> $options </select><br/>
Notes :<input name="notes" value="$hr->{'Notes'}"/><br/>
<input type="submit" name="go" value="UPDATE"/>
</form></div><hr/>!;

my $count = $dbh->do( $sql,undef,$empid );
$msg = "$count Record fetched - $sql, $empid";

} else {
print qq!<div class="container">
Select Employee to be updated :
<form method="post" action="">
<select name="empid"> $options </select><br/>
<input type="submit" name="go" value="FETCH"/>
</form></div><hr/>!;

# Standard links to the rest of the application
print <<"FOOTER";
<b>$msg</b>
<hr/>
Jump to - <a href="emp2.pl">View Employees Listing</a><br/>
Jump to - <a href="addemp.pl">Add an Employee</a><br/>
Jump to - <a href="updatephoto.pl">Add or update Employee Photo</a><br/>
<hr/>
Edited by Terry on July, 06 2014.
FOOTER
}
print $q->end_html;

# connect to database
sub dbh {
my $dsn = 'DBI:Pg:dbname=northwind;host=localhost';
my $user = 'postgres';
my $pwd = 'postgres';
my $dbh = DBI -> connect($dsn,$user,$pwd,{'RaiseError' => 1});
return $dbh;
}




Many thanks in advance.

Terry


Zhris
Enthusiast

Jul 7, 2014, 8:12 AM

Post #5 of 22 (2966 views)
Re: [terrykhatri531] How to get input text boxes populated [In reply to] Can't Post

Hi,

Briefly looking over:

1) put print statements inside conditions you are debugging to check they fall true.

2) it doesn't look as though you commit the update transaction by setting AutoCommit to 1 upon DBI instantiation, or preferably by calling $dbh->commit(); after the $dbh->do();.

Regards,

Chris


(This post was edited by Zhris on Jul 7, 2014, 8:16 AM)


terrykhatri531
User

Jul 7, 2014, 11:00 AM

Post #6 of 22 (2930 views)
Re: [Zhris] How to get input text boxes populated [In reply to] Can't Post

Hi,

I am monitoring the database logs I see all other queries being sent to the database except the UPDATE one so to your point no.2, my postgresql database is set to AutoCommit therefore unless I start a transaction with BEGIN; I don't have to commit it.



When you have the time PLEASE do have a closer look at the script I am 100% sure its not executing the UPDATE action but cannot figure out why !



Rgds

Terry


Zhris
Enthusiast

Jul 7, 2014, 11:27 AM

Post #7 of 22 (2918 views)
Re: [terrykhatri531] How to get input text boxes populated [In reply to] Can't Post

Hi,

Can you confirm that you have tested that you are definitely getting into the following condition by including an outer print statement, and an inner print statement. If not, then the outer print statement should provide clues as to why not. Otherwise this will atleast help us to narrow down your problem. P.s. that regexp matches any string that contains atleast 1 number.


Code
print "DEBUG: action=$action,empid=$empid\n"; 
if ( ($action eq "UPDATE") && ($empid =~ /\d+/)) {
print "DEBUG: beginning of UPDATE\n";
...
}


Update:

I just noticed that when fetching the data the employee id hidden field uses the name "EmployeeID", but you access with "empid". Try:


Code
my $empid = $q->param('empid'); 
my $empid = $q->param('EmployeeID');


But I would have assumed that your fetch, which also uses this parameter, would be broken too...

Regards,

Chris


(This post was edited by Zhris on Jul 7, 2014, 11:40 AM)


terrykhatri531
User

Jul 7, 2014, 12:18 PM

Post #8 of 22 (2890 views)
Re: [Zhris] How to get input text boxes populated [In reply to] Can't Post

Hi Chris,

I just ran Crap::Always and its giving me the following indication, see if it makes sense :




Code
  
perl -MCarp::Always edit2.pl
Use of uninitialized value $action in string eq at edit2.pl line 22 (#1)




The line 22 is the action UPDATE line.



The action FETCH is working fine that's how I get to the update form, I will get back to you on debugging once I figure it out and start it.



Many thanks

Rgds

Terry


(This post was edited by terrykhatri531 on Jul 7, 2014, 12:26 PM)


Zhris
Enthusiast

Jul 7, 2014, 12:32 PM

Post #9 of 22 (2880 views)
Re: [terrykhatri531] How to get input text boxes populated [In reply to] Can't Post

As suspected its the IF condition causing your warning.

Firstly, you probably want to give $action a default value i.e. the default action to perform when no action is supplied, that should resolve the warning. Perhaps it will be a good idea to do the same for $empid, since you don't appear to check if its defined anywhere either.


Code
my $action = $q->param('go') || 'FETCH';  
my $empid = $q->param('EmployeeID') || '' ;


Without being able to test your code, its difficult to tell how you are executing the script (assumably via the interface) and with what parameters (dump the parameter values at the top, inspect them, work back to find out why they aren't as expected).

Just noticed the select form used to choose which employee to display. Compare this field with the hidden one, you use two different names, as above, choose one or the other:


Code
<select name="empid"> $options </select><br/> 

<input type="hidden" name="EmployeeID" value="$hr->{'empid'}"/>


Regards,

Chris


(This post was edited by Zhris on Jul 7, 2014, 12:55 PM)


terrykhatri531
User

Jul 7, 2014, 1:00 PM

Post #10 of 22 (2856 views)
Re: [Zhris] How to get input text boxes populated [In reply to] Can't Post

Hi Chris,

I fully realize you cannot test it so its difficult to figure out what the problem is.



One simple question HOW WILL YOU REWRITE IT ?



Rgds

Terry


Zhris
Enthusiast

Jul 7, 2014, 1:08 PM

Post #11 of 22 (2852 views)
Re: [terrykhatri531] How to get input text boxes populated [In reply to] Can't Post

Terry,

Have you followed my advice?

Here all I have done is corrected your hidden form field (I also noticed you are calling the wrong hash key when assigning the value). I have not resolved the warnings as per my other advice.


Code
<input type="hidden" name="EmployeeID" value="$hr->{'empid'}"/>  
<input type="hidden" name="empid" value="$hr->{'EmployeeID'}"/>


Fingers crossed this will work:


Code
#!/usr/local/bin/perl  
use strict;
use CGI;
use CGI::Carp 'fatalsToBrowser'; #remove for prod
use DBI;

# get form parameters
my $q = new CGI;
my $action = $q->param('go');
my $empid = $q->param('empid');

my $dbh = dbh(); # connect to db
$dbh->do("SET search_path to northwind") or die;

# If the confirm form was properly submitted, update the record
my $msg;
# change validation to suit
if ( ($action eq "UPDATE") && ($empid =~ /\d+/)) {

my @data=();
my @fields = qw!lastname firstname title toc dob doh address city
region pcode country homephone ext repto notes !;
for my $f (@fields){
push @data,$q->param($f) || '' ;
}
push @data,$empid;

my $sql = qq!UPDATE "Employees"
SET "LastName" = ?,
"FirstName" = ?,
"Title" = ?,
"TitleOfCourtesy" = ?,
"BirthDate" = ?,
"HireDate" = ?,
"Address" = ?,
"City" = ?,
"Region" = ?,
"PostalCode" = ?,
"Country" = ?,
"HomePhone" = ?,
"Extension" = ?,
"ReportsTo" = ?,
"Notes" = ?,
WHERE "EmployeeID" = ? !;

my $count = $dbh->do( $sql,undef,@data);
$msg = "$count Record updated - $sql, @data";
} else {
$msg = "Please complete form";
}

# get employees
my $sql = qq!SELECT "EmployeeID" AS empid,
"FirstName"::text || ' ' ||"LastName"::text AS name
FROM "Employees" !;
my $ar = $dbh->selectall_arrayref($sql);

# Make up a pulldown menu
my $options = qq!<option value="">select name</option>!;
for my $row (@$ar) {
$options .= qq!<option value="$row->[0]">$row->[1]</option>\n!;
}

# build html page
my $style = q!
body { background-color: pink ; color: #3300cc; }
.container { width: 500px; clear: both; }
.container input { width: 100%; clear: both;}
!;

# Send out the header and form
print $q->header;
print $q->start_html(-title=>'Update an employee record',
-style=>{ -code=>$style } );
print qq!<h1 style="color:3300CC">Please update an employee</h1>!;

# Fetch data
if ( $action eq "FETCH" ) {
#print qq!<h3>Please make the necessary updates to $empid ?</h3>
my $sql = 'SELECT * FROM "Employees"
WHERE "EmployeeID" = ?';
my $hr = $dbh->selectrow_hashref($sql,undef,$empid);
#my $hr = $dbh->selectrow_hashref($sql,undef,$input{empid});

print qq!<div class="container">
<form action="" method="post">
Employee ID : $hr->{'EmployeeID'}<br/>
<input type="hidden" name="empid" value="$hr->{'EmployeeID'}"/>
Last Name :<input name="lastname" value="$hr->{'LastName'}"/><br/>
First Name :<input name="firstname" value="$hr->{'FirstName'}"/><br/>
Title :<input name="title" value="$hr->{'Title'}"/><br/>
Title Of Courtesy :<input name="toc" value="$hr->{'TitleOfCourtesy'}"/><br/>
Birth Date :<input name="dob" value="$hr->{'BirthDate'}"/><br/>
Hire Date :<input name="doh" value="$hr->{'HireDate'}"/><br/>
Address :<input name="address" value="$hr->{'Address'}"/><br/>
City :<input name="city" value="$hr->{'City'}"/><br/>
Region :<input name="region" value="$hr->{'Region'}"/><br/>
PostalCode :<input name="pcode" value="$hr->{'PostalCode'}"/><br/>
Country :<input name="country" value="$hr->{'Country'}"/><br/>
Home Phone :<input name="homephone" value="$hr->{'HomePhone'}"/><br/>
Extension :<input name="ext" value="$hr->{'Extension'}"/><br/>
Reports To :<select name="repto"> $options </select><br/>
Notes :<input name="notes" value="$hr->{'Notes'}"/><br/>
<input type="submit" name="go" value="UPDATE"/>
</form></div><hr/>!;

my $count = $dbh->do( $sql,undef,$empid );
$msg = "$count Record fetched - $sql, $empid";

} else {
print qq!<div class="container">
Select Employee to be updated :
<form method="post" action="">
<select name="empid"> $options </select><br/>
<input type="submit" name="go" value="FETCH"/>
</form></div><hr/>!;

# Standard links to the rest of the application
print <<"FOOTER";
<b>$msg</b>
<hr/>
Jump to - <a href="emp2.pl">View Employees Listing</a><br/>
Jump to - <a href="addemp.pl">Add an Employee</a><br/>
Jump to - <a href="updatephoto.pl">Add or update Employee Photo</a><br/>
<hr/>
Edited by Terry on July, 06 2014.
FOOTER
}
print $q->end_html;

# connect to database
sub dbh {
my $dsn = 'DBI:Pg:dbname=northwind;host=localhost';
my $user = 'postgres';
my $pwd = 'postgres';
my $dbh = DBI -> connect($dsn,$user,$pwd,{'RaiseError' => 1});
return $dbh;
}


Chris


(This post was edited by Zhris on Jul 7, 2014, 1:13 PM)


terrykhatri531
User

Jul 7, 2014, 1:45 PM

Post #12 of 22 (2832 views)
Re: [Zhris] How to get input text boxes populated [In reply to] Can't Post

Hi Chris,

Bad new it did not work, there's gotta be something else.

Addition: Sorry Chris for not being very explicit, the script you posted after changing one line to empid did not compile and had errors

so what I did I changed that line in my original script to :


Code
 
<input type="hidden" name="empid" value="$hr->{'empid'}"/>


and tested it, but still the same problem NO OUPT PUT WHEN I CLICK ON UPDATE.



Many thanks for your efforts.

Rgds

Terry


(This post was edited by terrykhatri531 on Jul 8, 2014, 1:56 AM)


Zhris
Enthusiast

Jul 7, 2014, 1:58 PM

Post #13 of 22 (2824 views)
Re: [terrykhatri531] How to get input text boxes populated [In reply to] Can't Post

Hi,

Oh well worth a try.

Could you expand on "it did not work". Did the script fail to compile / run. Or no output when you click the UPDATE button. Etc...

Could you dump the parameters after creating the CGI object / post them, then we can see what is actually being passed to the script:


Code
my $q = new CGI;  
my %parameters = $q->Vars;
use Data::Dumper;
print $q->header;
print Dumper \%parameters;



Chris


(This post was edited by Zhris on Jul 7, 2014, 2:12 PM)


terrykhatri531
User

Jul 8, 2014, 2:31 AM

Post #14 of 22 (2098 views)
Re: [Zhris] How to get input text boxes populated [In reply to] Can't Post

Hi Chris,

You got it, I knew you can do it and you did it, thank you very very much !!!

The script that you posted had some typos so what I did is to mistakenly made the changes to my script from EmployeeID to empid and ran it and there were again no results, just now I again ran over your posted script and changed my script from empid to EmployeeID and it works, YES the UPDATE works now !!



I do apologize again for not reading it correctly.

Rgds.

Terry


Zhris
Enthusiast

Jul 8, 2014, 8:38 AM

Post #15 of 22 (1685 views)
Re: [terrykhatri531] How to get input text boxes populated [In reply to] Can't Post

Hi Terry,

Glad to hear you got it working in the end.

Theres a skill to debugging CGI scripts, this was a case of finding out why the parameters didn't cause that IF condition to fall true. Luckily I spotted the mistakes. If you organize your code properly, these type of issues will be easier to discover / fix.

Regards,

Chris


terrykhatri531
User

Jul 9, 2014, 12:27 AM

Post #16 of 22 (1384 views)
Re: [Zhris] How to get input text boxes populated [In reply to] Can't Post

Hi Gurus,

What should be the Regex if data contains just alphabet letters for the following :




Code
 
if ( ($action eq "UPDATE") && ($custid =~ /\d+/)) {




CustomeIDs are like :




Code
 
CustomerID
------------
ALFKI
ANATR
ANTON
AROUT
BERGS
BLAUS
BLONP
BOLID




Many thanks

Terry


Zhris
Enthusiast

Jul 9, 2014, 1:26 AM

Post #17 of 22 (1381 views)
Re: [terrykhatri531] How to get input text boxes populated [In reply to] Can't Post

Hi Terry,

For uppercase A to Z use:


Code
/^[A-Z]+$/


Regards,

Chris


terrykhatri531
User

Jul 9, 2014, 2:04 AM

Post #18 of 22 (1378 views)
Re: [Zhris] How to get input text boxes populated [In reply to] Can't Post

Many thanks Chris!!

Another quick question, how do I align numeric data to right in HTML::Template




Code
 
<!-- TMPL_LOOP NAME=ROWS -->
<tr>
<td><!-- TMPL_VAR NAME=ProductID --></td>
<td><!-- TMPL_VAR NAME=ProductName --></td>
<td><!-- TMPL_VAR NAME=CompanyName --></td>
<td><!-- TMPL_VAR NAME=CategoryName --></td>
<td><!-- TMPL_VAR NAME=QuantityPerUnit --></td>
<td><!-- TMPL_VAR NAME=UnitPrice --></td>
<td><!-- TMPL_VAR NAME=UnitsInStock --></td>
<td><!-- TMPL_VAR NAME=UnitsOnOrder --></td>
<td><!-- TMPL_VAR NAME=ReorderLevel --></td>

<td><!-- TMPL_VAR NAME=Discontinued --></td>
</tr>
<!-- /TMPL_LOOP -->


Many many thanks !!

Terry


Zhris
Enthusiast

Jul 9, 2014, 2:15 AM

Post #19 of 22 (1376 views)
Re: [terrykhatri531] How to get input text boxes populated [In reply to] Can't Post

Hi,

Use HTML's align attribute OR CSS's text-align property.

http://www.w3schools.com/tags/att_td_align.asp
http://www.w3schools.com/cssref/pr_text_text-align.asp

Regards,

Chris


(This post was edited by Zhris on Jul 9, 2014, 2:19 AM)


terrykhatri531
User

Jul 9, 2014, 2:17 AM

Post #20 of 22 (1374 views)
Re: [Zhris] How to get input text boxes populated [In reply to] Can't Post

Hi,

New regex validation did not work !!


Code
 
if ( ($action eq "UPDATE") && ($custid =/^[A-Z]+$/)) {


Rgds.

Terry


Zhris
Enthusiast

Jul 9, 2014, 2:21 AM

Post #21 of 22 (1372 views)
Re: [terrykhatri531] How to get input text boxes populated [In reply to] Can't Post


Code
($custid =/^[A-Z]+$/) 
($custid =~ /^[A-Z]+$/)


Regards,

Chris


terrykhatri531
User

Jul 9, 2014, 3:15 AM

Post #22 of 22 (1354 views)
Re: [Zhris] How to get input text boxes populated [In reply to] Can't Post

Many thanks !!

Terry

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives