Gossamer Forum
Home : Products : DBMan : Customization :

Limit Character Length

Quote Reply
Limit Character Length
Quick Question for you all. In my sub signup in db.cgi, I have added the line

$in{'userid'} = $in{'fn'} . $in{'ln'};

This will allow me to take the First Name & Last name from the html signup form, and create a user id. What i need to find out is, what coding would I use to make the First name one initial (i.e. They enter Chris as their name, and it shortens it to C). I would also need to use this for the last name field, to cut it down to 11 characters - forming a 12 character userid.

Thanks for any help you can give!

Chris Kinsler

Quote Reply
Re: Limit Character Length In reply to
Give the following a try:

$first_initial = substr($rec{'fn'}, 0, 1);
$last_name = ((length($rec{'ln'}) < 12) ? $rec{'ln'} : (substr($rec{'ln'}, 0, 11)));

$in{'userid'} = $first_initial . $last_name;

This will take the first character form the first name, then the first 11 characters from the last name (unless the last name is only 11 or less characters, in which case it will just take the whole last name)

Hope this helps

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Limit Character Length In reply to
Mark,
Gave that a shot, and it comes back everytime with "Invalid userid: . Must only contain only letters and be less then 12 and greater then 3 characters."

Any ideas as to why it's not processing the fields correctly?


Thanks!
Chris

Quote Reply
Re: Limit Character Length In reply to
Woops! Sorry, my bad Blush

It should be $in, not $rec:

$first_initial = substr($in{'fn'}, 0, 1);
$last_name = ((length($in{'ln'}) < 12) ? $in{'ln'} : (substr($in{'ln'}, 0, 11)));

$in{'userid'} = $first_initial . $last_name;

Sorry, should have a bit more luck now Smile

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Limit Character Length In reply to
Still Coming back with the same error =(

Any ideas?

Thanks Again,
Chris

Quote Reply
Re: Limit Character Length In reply to
Hmmm...

May I see your full code? Might be able to get a better idea of whats happening.

- Mark

PS: post your html.pl and db.cgi in a web accessible area rather than to the forum

Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Limit Character Length In reply to
Here you go....
http://www.aresva.org/dbman/

Thanks!
Chris

Quote Reply
Re: Limit Character Length In reply to
Ok, I think I see the problem, in your signup form, you have:
<input name="Last_Name" value="$in{'ln'}" size="20">

So when you submit the form, the value becomes $in{'Last_Name'}, but we were looking for $in{'ln'}. Anyway, to cut a long story short, replace each occurance of ln with Last_name and fs with First_Name. So now we have:

$first_initial = substr($in{'First_Name'}, 0, 1);
$last_name = ((length($in{'Last_Name'}) < 12) ? $in{'Last_Name'} : (substr($in{'Last_Name'}, 0, 11)));
$in{'userid'} = $first_initial . $last_name;

Fingers crossed! Smile

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/
Quote Reply
Re: Limit Character Length In reply to
Yup - that did it! One problem that I did encounter though...when the system generates the userid, its in all capitals. I think this is because I have installed the all caps mod for some of my fields (which include record fields First_Name and Last_Name). I tried switching these fields on the signup form to something different again (fn/ln), but I got the same error we've been getting.

Is there any way to change the case of the userid field to lower case (after the userid = first_initial . Last_name statement)? or...an alternative would be to change the signup field names to something different (if I could get it to work).


Thanks again!

Chris

Quote Reply
Re: Limit Character Length In reply to
Absolutely, under the line:
$in{'userid'} = $first_initial . $last_name;

Just add the following:
$in{'userid'} =~ tr/A-Z/a-z/;

Cheers,

- Mark

Astro-Boy!!
http://www.zip.com.au/~astroboy/