?
Solved

Dynamic Max Length Setup

Posted on 2005-04-07
12
Medium Priority
?
227 Views
Last Modified: 2013-12-24
I have 15 odd form fields that i need to setup their maxlengths that are taken from a SQL table but i am having problems trying to figure out how to associate each database max length value with each form field !?


For Example...

Table
jobboardid   fieldidfk            maxlength
   1                  1                     100
   2                  1                      75
   3                  2                      75
   4                  2                      50

select fieldfk,min(maxlength)
from table
group by fieldfk

Output
fieldfk       min(maxlength)
1                 75
2                 50

Form Field

<input name="name" value="#FORM.name#" type="text" maxlength=" ??????????" />

What would be the best way to set this up for the 15 form fields, maybe using cfif's compares ??

Cheers

JT
0
Comment
Question by:jturkington
  • 4
  • 3
  • 3
  • +1
12 Comments
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 13728706
Hello,

SELECT MAX(field1) AS FieldCountOne, MAX(field2) AS FieldCountTwo, MAX(field3) AS FieldCountThree
FROM YourTable

<input name="name" value="#FORM.name#" type="text" maxlength="#FieldCountOne#"/>....



>>What would be the best way to set this up for the 15 form fields, maybe using cfif's compares ??  not sure what yo mean....
I would prefer <cfscript> less clutter, faster?
0
 
LVL 21

Assisted Solution

by:pinaldave
pinaldave earned 400 total points
ID: 13728725
Hi jturkington,
<cfquery name="yourquery" datasource="dsn">
select fieldfk,min(maxlength) as yourlength
from table
group by fieldfk
</cfquery>

<cfloop query="yourquery">
<input name="name" value="#yourquery.fieldfk#" type="text" maxlength="#yourquery.yourlength#" />

</cfloop>


This is concept you can modify as per your requirement.


Regards,
---Pinal
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 13728731


This may be better to use..

SELECT COUNT(field1) AS FieldCountOne, COUNT(field2) AS FieldCountTwo, COUNT(field3) AS FieldCountThree
FROM YourTable
0
Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

 

Author Comment

by:jturkington
ID: 13728749
trailblazzyr55 i dont have individual columns for each form field they are all in the column fieldidfk
0
 
LVL 20

Expert Comment

by:trailblazzyr55
ID: 13728760
errrr. read the question wrong ;^)

pinaldave's should work :o)
0
 

Author Comment

by:jturkington
ID: 13728775
pinaldave i have a three of four textarea fields how do i get around this ?!?
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 13728785
Hi jturkington,
I did not understand what does it mean by three of four textarea

Regards,
---Pinal
0
 
LVL 21

Expert Comment

by:pinaldave
ID: 13728791
Hi jturkington,
if you mean to say that there three textarea the maxlength will not work. you need some javascript validation for that. or serverside validation(which only works with submit)

Regards,
---Pinal
0
 

Author Comment

by:jturkington
ID: 13728823
ahh i see pinaldave, looks like i have to manually enter the max lengths as and when they change for each form field !
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 1600 total points
ID: 13728846
jturkington -- You can't get around it for textareas.  The best you can do (since there is no maxlength) is to have the CF dynamically create javascript to test each field's inputted number of characters and not submit if the length is long.

Also (notice not OR), you need to check on the backend when the form is submitted that the textareas are not too long (since people can disbale javascript.

Look Here:
http://www.blueshoes.org/en/javascript/limitedtextarea/ (function examples)

Or Here:
http://www.uwex.edu/infosys/ads/repository/paste/34 (inline example)
0
 

Author Comment

by:jturkington
ID: 13728859
Is there no way to setup 15 variables at the start of the form
eg

Field1maxlength = query.maxlength1
Field2maxlength = query.maxlength2
etc..

and use the variables on the form to set max length and server side validation ??
0
 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 1600 total points
ID: 13729492
you could set variables on the form and then send those into the javascript, but not into server side.  You really want the server side to re-query the database values when performing the validation.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month17 days, 7 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question