Need help changing form input to leading caps on certain entries 
Author Message
 Need help changing form input to leading caps on certain entries

Hi just learning here and looking for help. (so forgive the terminology)

I have a script that takes entries from a form and inserts it into a page
template, to write, and display a new  html page.

While it works I would like it to change some entries to leading uppercase
for the first letter of each, if entered in all lower case
eg: " Name"  rather than "name"
While I can do this for all the entries, some I would like to leave as they
are typed

names, address', forced to leading caps,  -  additional comments taken
through a text area left as is

----------------------------------------------------------------------------
------------------------
#!/usr/bin/perl
read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});


 {
  ($key,$content)=split(/=/,$item,2);
  $content=~tr/+/ /;
  $content=~s/(\w+)/\u\L$1/g;
  $fields{$key}=$content;
 }
print "Content-type: text/html\n\n";
print "<html><
----------------------------------------------------------------------------
--------------------------
this changes all entries to first letter upper case on each word

----------------------------------------------------------------------------
--------------------------
#!/usr/bin/perl
read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});


 {
  ($key,$content)=split(/=/,$item,2);
  $content=~tr/+/ /;
  $content=~s/%(..)/pack("c",hex($1))/ge;
  $fields{$key}=$content;
 }
print "Content-type: text/html\n\n";
print "<html><
----------------------------------------------------------------------------
---------------------------
this leaves all entries as is.

how can I specify to have some entries  one way and some the other ?

a quick fix would be great, but I would also like to find a source on the
web where I can learn more about this.

Thanks

Gypsy



Sun, 16 May 2004 21:54:41 GMT  
 Need help changing form input to leading caps on certain entries

Quote:

> Hi just learning here and looking for help. (so forgive the terminology)

> I have a script that takes entries from a form and inserts it into a page
> template, to write, and display a new  html page.

> While it works I would like it to change some entries to leading uppercase
> for the first letter of each, if entered in all lower case
> eg: " Name"  rather than "name"
> While I can do this for all the entries, some I would like to leave as they
> are typed

> names, address', forced to leading caps,  -  additional comments taken
> through a text area left as is

> ----------------------------------------------------------------------------
> ------------------------
> #!/usr/bin/perl
> read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});



>  {
>   ($key,$content)=split(/=/,$item,2);
>   $content=~tr/+/ /;
>   $content=~s/(\w+)/\u\L$1/g;
>   $fields{$key}=$content;
>  }

[...]

Quote:
> how can I specify to have some entries  one way and some the other ?

You bring yourself into trouble by using a not so very appropriate
data-strcture for the key/value pairs. Instead read about the benefits
of using the CGI-module ('perldoc CGI'). With that, you can comfortably
pull in the parameters into a hash and - based on the the keys - change
the values accordingly:

#! perl -wT

use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser); # for outputting errors to the
                                   # browser

my $q = new CGI;

# pull in the parameters:
my %params = $q->Vars;

for my $key (%params) {
    $params{$key} = ucfirst $params{$key} if $key eq 'address';
    ...

Quote:
}
> a quick fix would be great, but I would also like to find a source on the
> web where I can learn more about this.

As pointed out, the manpages for CGI are a good source. And even better:
You have plenty to read. ;-)

Tassilo
--
Learning at some schools is like drinking from a firehose.



Sun, 16 May 2004 22:35:19 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Newb needs help with input from forms

2. form input changed from Select to hidden, no errors and no search results

3. Changing Form Input via Perl Script/Mail Script

4. help for Checking input to match a certain pattern

5. Changing UPPERCASE to Initial Caps

6. need to retrieve html form input type data

7. need perl module to get form input

8. Reading text files where same word is spelled wtih all caps or no caps

9. need to retrieve html form input type data

10. help needed: remove leading/trailing blanks

11. help!!-script to read and output the input from Mosaic Forms

12. Validating user input to match certain characters

 

 
Powered by phpBB® Forum Software