• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Dynamic Form to Dynamic Action Page

Community Beginner ,
Aug 10, 2006 Aug 10, 2006

Copy link to clipboard

Copied

Hi,
I am trying to build a simple form which includes 4 fields:
2 Text fields: FirstName, LastName, 1 select field: Role, and one dynamic hidden field

I am looking to accomplish 2 things:

1. I want the value of the hidden field to by dynamic from the data of firstname and lastname and reformated to "lastname, firstname".
2. The name of the in the hidden field must also be dynamic where the name would equal the value of the selected role

FYI, In my database I do not have a field called "role" but i do have a field for every item in the role field.

Any ideas or sample code to share?
All help is greatly appreciated.
Thanks!
TOPICS
Advanced techniques

Views

373

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 10, 2006 Aug 10, 2006

Copy link to clipboard

Copied

That is not a very good database design for future development.

But to do what you want, if I understand your question correctly, you do
not need to create a hidden form field.

I can imagine two possible solutions on the action page. If you really
want it to be a form value for some reason. This should work:

<cfset form[form.role] = true> <!--- OR whatever value you want this
field to be. --->

OR if you are writing your own queries, you should be able to just do this.

<cfquery ....>
INSERT INTO aTable
(firstName, lastName, #form.role#)
VALUES
('#form.firstName#, #form.lastName#, true)
</cfquery>

Mikelaskowski wrote:
> Hi,
> I am trying to build a simple form which includes 3 fields:
> 2 Text fileds: FirstName, LastName, and 1 secet field: Role
>
> I am looking to accomplish 2 things:
>
> 1. I want the form to take the data from the firstname and last name fields
> and create a hidden field where the name of the the hiddden fields is named
> after the selected Role.
>
> FYI, In my database I do not have a field called "role" but i do have a field
> for every item in the role.
>
> Any ideas or same code to share?
> All help is greatly appreciated.
> Thanks!
>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 10, 2006 Aug 10, 2006

Copy link to clipboard

Copied

To accomplish exactly what you describe, you would have to use JavaScript. But why not simplify it. See code below.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 10, 2006 Aug 10, 2006

Copy link to clipboard

Copied

Thanks,
I really like your solution. It definatly sounds a lot easier.
I am still having a little trouble though. I am probably missing something silly (especially in my cfupdate tag) as I am a little new at this stil.

When I used your code in my action page I get the following error:
Error Occurred While Processing Request
Variable PRESIDENT is undefined. <--when president is selected in the role field. It changes nicely when another is selected.

Here is my current code on my action page:
------------------------------------------------------------------

Thanks Again!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 10, 2006 Aug 10, 2006

Copy link to clipboard

Copied

LATEST
<cfupdate> process data from the form scope. You are not putting your
role datum into the form scope. You need to scope the variable in your
cfset(s).

<cfset form.roleColumn = form.role=>

But I am not sure this would work well. It is probably better if you
write your own SQL. <cfinsert> and <cfupdate> are for very basic
database operations. Once you start putting other processing
requirements in, such as this, they quickly become inadequate.

Try replacing your <cfupdate> with a <cfquery> tag something like this.

<cfquery datasource="my_DSN">
UPDATE my_table
SET lastName = '#form.lastName#',
firstName = '#form.firstName#',
#form.role# = true
WHERE key = value
</cfquery>

I made my best guesses at how this SQL would look based on the examples
you have provided. You'll have to finish it off based on your actual
requirements.

Mikelaskowski wrote:
> Thanks,
> I really like your solution. It definatly sounds a lot easier.
> I am still having a little trouble though. I am probably missing something
> silly (especially in my cfupdate tag) as I am a little new at this stil.
>
> When I used your code in my action page I get the following error:
> Error Occurred While Processing Request
> Variable PRESIDENT is undefined. <--when president is selected in the role
> field. It changes nicely when another is selected.
>
> Here is my current code on my action page:
> ------------------------------------------------------------------
>
> Thanks Again!!!
>
> <CFSET lastFirst = lastName & ", " & firstName>
> <CFSET roleColumn = Evaluate(role)>
> <cfupdate datasource="my_DSN" tablename="my_table">
> <html>
> <head>
> <title>Title</title>
> </head>
> <body>
> <cfoutput>The role is #roleColumn#<br>
> The value is #lastFirst#</cfoutput>
> </body>
> </html>
>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation