Dynamic Form field name

I have a shopping cart that creates a dynamic field for the
quantity of each product in the cart. I need to be able to make
sure the user does not submit a blank value. I can not use cfinput
as per client instructions. The field is:
<input name="Quant_#GetCart.ShowID#" type="Text"
value="#GetCart.Quantity#" size="1" maxlength="2"
title="Quantity"/>
How would you go about validating Quant_#GetCart.ShowID#?
Thanks in advance for the help/suggestions.

LeftCorner,
Thanks for the compliments, and for analyzing my code. It's
cool to see you care. I agree that the find() should have been
findNoCase(), and the inclusion of a trim() could be a good one,
however, the evaluating is not better. In general, Evaluate() is
becoming less used, and is being certainly phased out where it's
not extremely necessary. There are a few arguments as to why,
performance being one of them, readability being another. I stand
by my code and I recommend you check out structure notation
(structure[key] when you would normally write structure.key except
you don't know what "key" really is) wherever possible.

Similar Messages

  • Please help with dynamic form field names in cfloop

    Hi,
    I need to create a form with day, date, month, year and time for 12 months
    Instead of coding them 12 times, I create day,date,month,year and time fileds in my form 1 time and then I use cfloop from="1" to="12" index="i" to loop these form fields 12 times.
    I gave each form field name such as: <input type="text" name="ScheduleDate_# i #" value=" "> this way each of those field will be named differently such as:
    ScheduleDate_1, ScheduleDate_2,ScheduleDate_3, ScheduleTime_1,ScheduleTime_2, etc
    I'm facing problem when this form is submitted, I think the error has something to do with the pound sign (##) when it comes to updating the back end
    I use MS SQL
    It doesn like this:
    <CFLOOP From="1" To="12" index="k">
    <CFIF Len(Trim(Form.MeetYear_#k#)) NEQ 0 AND Len(Trim(Form.MeetTime_#k#)) NEQ 0>
    <cfquery name="CreateSchedule" datasource="#DSN#">
    UPDATE TableSchedule 
    SET SchedDay = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.SchedDay_#k##">,SchedMonth =
    <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.SchedMonth_#k##">,SchedDate =
    <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.SchedDate_#k##">,SchedYear =
    <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.SchedYear_#k##">,SchedTime =
    <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.SchedTime_#k##">
    Where SchedId = <cfqueryparam cfsqltype="cf_sql_numeric" value="#k#">  
    </cfquery>
    </CFIF>
    </CFLOOP>
    Can anyone help please?

    You can't nest hash marks. Do this instead:
    SET SchedDay = <cfqueryparam cfsqltype="cf_sql_varchar" value="#form["SchedDay_" & k]#">
    Dave Watts, CTO, Fig Leaf Software
    http://www.figleaf.com/
    http://training.figleaf.com/

  • Evaluating dynamically generatedform  field names

    On form submission I need to find out if check boxes exist
    and have values. The field names are generated dynamically &
    there could be many. Here's the code I've been messing with. I am
    able to find out it the field has a value if it exists, but I can't
    figure out how to combine this with isDefined("") to test for the
    field's existence and avoid the "field i not defined in form"
    errors.
    <cfloop index="a" from="1" to="#form.numRows#">
    <cfset thisname = "form." & #a# & "_Clear">
    <!--- how do I use isDefined("") at this point to avoid
    an error on the next line when the field does not exist? --->
    <cfset thisVal= Evaluate("form.#thisname#")>
    <cfoutput> #thisname# #thisVal# </cfoutput>
    </cfloop>
    Thanks in advance for any help!

    run a loop over your field names like: <cfloop index="x"
    list="#form.fieldnames#"> then you have all of your form field
    names that are defined.

  • Cfoutput query and form field names

    I have a form that have two field inputs. I would like to repeat the form fields as part of a cfoutput query. The first field of the form automatically populates the different person's name (via cfoutput query) and this form field is called "tenant". The next field of the form is called "sales". The sales field is left open for user imput. The entire form is in between the cfoutput query tags. When the cfoutput query is executed, Both form fields of the form is displayed with each tenant name listed in each of the first form fields of each row. The problem I'm running into is that even though the form elements appear to display correctly, I would like the name of each of my form elements in the cfoutput query, of each row to have a different form field name like, tenant2, sales2, tenant3, sales3 etc. is that possible?
    Here's what my code look like.
    <cfform action= "addsales.cfm" method="post">
    <cfoutput query="tenantsales"><Input name="tenant" type="text" value="#office.tenant#" size="32" />
    <select name="sales"><option>$5</option><option>$10</option><option>$12</option></br></cfoutput>
    <input name="submit" type="submit" />
    </cfform>

    I cannot imagine why you would want to show a list of pre-populated input fields. What makes sense to me is a select-box. If that is indeed what you want, then you could do something like this:
    <cfform action= "addsales.cfm" method="post">
    <cfselect name="tenant">
        <option value="">Tenant</option>
    <cfoutput query="tenantsales">
        <option value="#tenantsales.tenantID#">#tenantsales.tenantName#</option>
    </cfoutput>
    </cfselect></br>
    <cfselect name="sales">
    <option value="">Sales</option>
    <option value="5">$5</option>
    <option value="10">$10</option>
    <option value="12">$12</option>
    </cfselect></br>
    <cfinput name="submit" type="submit" value="Submit" />
    </cfform>
    Like Dan, I have assumed your database table has a column for tenant ID.

  • How to make dynamic form fields update?

    This is going to be an ugly post, fair warning! :)
    I have a form that gets it's labels and text input field
    names dynamically from a database. Rather than having the form
    hardcoded, we are able to add new columns to a table and the form
    automatically adds new labels and fields via CFQUERY.
    When the form is completed and they submit (method post), the
    database is supposed to update. However, because our input field
    names are being populated via query, we can't write a static update
    query when we add new form items.
    So, I do have a solution to this (in my head), but I'm stuck
    at a bit of logic and am having trouble getting it out in code. I'm
    looking for a way to write #FORM.#fieldname## (here is where it
    gets ugly). Since the form submits by post method, I am left with a
    bunch of FORM.fieldname's on my action page (and fieldname is
    generic for what the actual variables are).
    So here's how I am updating:
    I have a table (call it table1) that contains a column of all
    the column names of my data table (table2). This table is used for
    query purposes only, no data is updated here from the form.
    I query table1 to call all the names of the columns in
    table2.
    <cquery datasource="exdb" name="exname">
    SELECT columnName
    FROM table1
    </cfquery>
    Then I write the update query which will update items as they
    are looped using CFOUTPUT:
    <CFOUTPUT QUERY="exname">
    <cfquery datasource="exdb" name="exupdate">
    UPDATE table2
    SET #columnName# = #FORM.<columnName>#
    WHERE itemID = #FORM.itemID#
    This is my dilemma. As you can see, the cfoutput is a loop..
    so let's take the first item in the loop, call it "name1". So our
    update query says SET name1 = #FORM.name1#, and this will update
    the table with whatever was submitted in name1's input field. The
    cfoutput loops again, this time it's name2. SET name2 =
    #FORM.name2#. Now the form does include a hidden input of itemID to
    specify where the table should be updating, as you can see above.
    So, now that you see how this works, my problem is getting
    #FORM.<columnName># to be FORM.name1, FORM.name2, etc.
    In Coldfusion you would write #FORM.variable# to call a FORM
    item. However, since the variable is pretty much undefined and we
    use a query to populate it, we need to do #FORM.#variable## where
    #variable# needs to be resolved before #FORM._______#
    Are you with me on this? It's very complex in explanation,
    but if you need more info, I can provide it more clearly. Let me
    know what you guys think. Really, I have the solution, but getting
    #FORM.#columnName## to resolve is another problem. I think what i
    need is to figure out the order of operation for that statement, so
    #columnName# resolves first.

    You'll want to use the scope structure notation when dealing
    with your form variables. The variable Form.SomeVar can also be
    written as Form["SomeVar"]. Using this syntax, you can do something
    like this:
    UPDATE table2
    SET #columnName# = #FORM[columnName]#
    WHERE itemID = #FORM.itemID#
    You may also want to look into the following to help optimize
    your code:
    1) check out how to use <cfqueryparam> - it might speed
    your code up a bit.
    2) depending on the DB you are using, you may be able to
    combine all of your UPDATE SQL commands inside 1 <cfquery>
    </cfquery> block. This will allow you to do all your database
    actions with 1 DB connection, instead of a bunch (works in MSSQL,
    not sure about Oracle or MySQL)

  • Dynamic form input name

    Hi,
    My brain is frozen or something because I couldn't think out this issue.  Basically my form input radio name and value are dynamically pulled from a database.  The name of the form is concat with a name and id is from a database.  On the form processing side, how would I get all the dynamic input radio name.  The value of the input will be attach to the name.  Hope that make sense. 
    form.cfm
    <cfquery name="get_form_name" datasource="#ds#">
         SELECT id, name
         FROM records
    </cfquery>
    <cfoutput>
    <form action="form_process.cfm">
    <cfloop query="get_form_name">
    <p>name: <input type="radio" name="test_#get_form_name.id#" value="#get_form_name.name#" /></p>
    </cfloop>
    <input type="submit" value="submit">
    </form>
    </cfoutput>
    form_process.cfm
    somehow get all the input name from the FORM to set cfparam and value.  Once I have this, i have the form values that are passing over.

    Your requirement is that you want the application to remember the name of a query variable across multiple page requests. That is a typical case where you would use the session scope.
    Following your example,
    form.cfm
    <cfquery name="get_form_name" datasource="#ds#">
         SELECT id, name
         FROM records
    </cfquery>
    <cfset session.formRecords = structNew()>
    <form action="form_process.cfm" method="post">
    <cfoutput query="get_form_name">
    <p>name: <input type="radio" name="test_#id#" value="#name#" /></p>
    <cfset session.formRecords["test_#id#"] = name>
    </cfoutput>
    <input type="submit" name="sbmt" value="submit">
    </form>
    form_process.cfm
    <!--- The names and values of the form fields are stored, respectively, as key-value pairs in the structure session.formRecords--->
    <cfdump var="#session.formRecords#">
    Remarks
    1) I simplified the code somewhat. I also added post method to the form, as I assume that is what you are aiming for. Otherwise the form fields will be submitted via the URL.
    2) It seems to me the database table holds rows having distinct values of ID . Therefore, my guess is that the functionality you should be going for is <input type="checkbox"> instead of <input type="radio">.

  • Is there a way to rename multiple form field names with a "b" at the end?

    I have a two page form, both are identical.  I need to rename all the field names on page 2 with a "b" at the end of the file name so they dont conflict with that of the first page.  Is there any fast way of doing this without renaming each individual one at at time?  I have a LOT to do!

    It's not possible with JavaScript. The name property of a field is read-only.
    I would suggest making a template from the first page and then spawn a new page from it.
    If you do it from a script make sure you set the bRename property to true and the form fields will be automatically renamed, but you can't specify the name, it will be in following pattern:
    P<Page Number>.<Template Name>.<Original Field Name>

  • Passing form field name to the subject line of the task assign email

    Hello Everyone,
    I am trying to create a process that need to pass one of the field data from a form to the task email assign but could not make it work right as expected. I think I miss something but could not figure it out myself. If any one has done this before, please share your knowledge.
    Thanks in advance,
    Han Dao

    Hi Jasmin,
    I thought it simple thing to do by passing the xPath to the subject line but for some reasons, it does not work instead it show the whole xpath on the subject line. Here is my xpath:
    {$/process_data/FormData/object/data/xdp/datasets/data/FSFIELDS_/Form1936/EmpInfoSub/UserM gr$}
    where Form1936 is the pageName, EmpInfoSub is sub-form, and UserMgr is field name on the form.
    Thanks,
    Han Dao

  • HR - dynamic selections field name and field value in the program

    HI all,
       I am using dynamic selections for a HR report.
    I have created a view with 20 fields and added it to HR report category ___00003(All fields suppressed).
    I need to check these fields in the program. But i am not able to get the field name and value in the program for dynamic selections fields.
    Please let me know how to get the field names and values in the program for dynamic selections .
    Thanks,
    Kranthi.

    You have to read the itab <i>pnpdynse</i> in your Program to obtain the Dynamic Selection values. This itab has a deep structure.. you can set a break point in one of the events before <b>get pernr</b> & in the debug mode, you will able to display the itab <i>pnpdynse</i>.. you can then identify how to get the values into your code..
    ~Suresh

  • How to dynamically list field names

    Hello,
    I have a DB Link to a SQL 2000 Server and can connect and retrieve using Heterogenous Servives.
    Let say I issued a Select (eg., Select * from tab@remote1), how do I dynamically list each field name from the result?
    Thank you.

    The best way to deal with dynamic column names from a SQL result is to use a cursor describe interface.
    A SQL SELECT may not select all the columns from a table. It may join tables. It may add derived and calculated columns to the result.
    None of these will be seen when using the data dictionary. Also, using a remote heterogeneous data dictionary? That does not sound like a sensible approach to me.
    In PL/SQL, one can create DBMS_SQL cursors. These cursors can be "described" - i.e. the describe interface for a cursor tells you what the contents are, the column names, the data types, the precision, etc.
    Using DBMS_SQL allows you to describe any result set from any SELECT statememt. A far superior and accurate method than to go data dictionary hunting to determine just which column could be in a result set.

  • How to make Form Field names appear for User??

    Hi im creating a form template that will be sent to over 150 stores so I need this to work and be easier for my stores.
    Is is possible to make the field names visable for the user so they know what details are need in the fields?
    Please if anybody can help!!

    Sorry I forgot to mention I need it to visible on Text boxes, doesnt seem to be working

  • Dynamic form fields collection order?

    I have a basic dynamic form feild with Instances that allow a user to enter data in a Table Row then, if neededed, ADD another row/instance to enter more.
    The form worls well and is processed via Adobe.com Tracker.
    Tracker and the exports to .csv of the data adds all the instances of new rows to the END of the spreadsheet and tracker form responses dispaly..  In other words it seems to process the entire form and all its fields in order, ignoring any new instances, THEN goes back and begins collecting the instances adding them to the end columns of the response spreadsheet.  Would be much easier to parse/read/collect responses if any new instances were collected and recorded next to the same location where the first instance occurred.
    Hope that makes sense.  For example if I had:
    FirstName
    LastName
    Date
    field
    field
    field
    field
    dynamic field (with otpion to add additional items/entries)
    field
    field
    field
    filed
    The data collection would appear as:
    FirstName
    LastName
    Date
    field
    field
    field
    field
    dynamic field (with otpion to add additional items/entries)
    field
    field
    field
    filed
    dynamic field extra entry 1
    dynamic field extra entry 2
    dynamic field extra entry 3
    But I would prefer is to appear as:
    FirstName
    LastName
    Date
    field
    field
    field
    field
    dynamic field (with otpion to add additional items/entries)
    dynamic field extra entry 1
    dynamic field extra entry 2
    dynamic field extra entry 3
    field
    field
    field
    filed
    ... with the dynamic new isntances collected and recorded adjacent to each other.  Doesnt seem like much until you have a long form with multiple new instance form options and all new instances seem to be arbitrarily thrown onto end of collection spreadsheet.
    Many thnaks!

    I have a basic dynamic form feild with Instances that allow a user to enter data in a Table Row then, if neededed, ADD another row/instance to enter more.
    The form worls well and is processed via Adobe.com Tracker.
    Tracker and the exports to .csv of the data adds all the instances of new rows to the END of the spreadsheet and tracker form responses dispaly..  In other words it seems to process the entire form and all its fields in order, ignoring any new instances, THEN goes back and begins collecting the instances adding them to the end columns of the response spreadsheet.  Would be much easier to parse/read/collect responses if any new instances were collected and recorded next to the same location where the first instance occurred.
    Hope that makes sense.  For example if I had:
    FirstName
    LastName
    Date
    field
    field
    field
    field
    dynamic field (with otpion to add additional items/entries)
    field
    field
    field
    filed
    The data collection would appear as:
    FirstName
    LastName
    Date
    field
    field
    field
    field
    dynamic field (with otpion to add additional items/entries)
    field
    field
    field
    filed
    dynamic field extra entry 1
    dynamic field extra entry 2
    dynamic field extra entry 3
    But I would prefer is to appear as:
    FirstName
    LastName
    Date
    field
    field
    field
    field
    dynamic field (with otpion to add additional items/entries)
    dynamic field extra entry 1
    dynamic field extra entry 2
    dynamic field extra entry 3
    field
    field
    field
    filed
    ... with the dynamic new isntances collected and recorded adjacent to each other.  Doesnt seem like much until you have a long form with multiple new instance form options and all new instances seem to be arbitrarily thrown onto end of collection spreadsheet.
    Many thnaks!

  • XSLT for dynamic target field names

    Hello,
    I got a requiremt where I need to create target field names from input values.
    Input XML -
    <?xml version="1.0" encoding="UTF-8"?>
    <Createelement_MT>
    <Field Name="A">
    <Value>1</Value>
    </Field>
    <Field Name="B">
    <Value>1</Value>
    </Field>
    </Createelement_MT>
    Expected OutPut XML -
    <?xml version="1.0" encoding="UTF-8"?>
    <Createelement_MT>
    <Statement><TableName><table>XYZ</table>
    <access>
    <A> 1 </A>
    <B> 2 </B>
    </access>
    </Statement></TableName>
    </Createelement_MT>
    The value of the attribute 'Name' of field 'Field' should be the name of target field.
    XSLT:
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"/>
    <xsl:template match="@*|node()">
    <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
    </xsl:template>
    <xsl:template match="Createelement_MT">
    <xsl:element name="statement">
    <xsl:element name="TableName">
    <xsl:element name="table">ABC</xsl:element>
    <xsl:element name="access">
    <xsl:for-each select="Field">
    <xsl:element name="{@Name}">
    <xsl:value-of select="Value"></xsl:value-of></xsl:element></xsl:for-each>
    </xsl:element>
    </xsl:element>
    </xsl:element>
    </xsl:template>
    </xsl:stylesheet>
    Error:
    Error: at xsl:element on line 15 of file:///......: XTDE0820: Invalid element name. Invalid QName {}
    Please help me with the xslt code for this requirement.
    Thanks!

    Hi,
                Please try this code
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
         <xsl:output method="xml"/>
         <xsl:template match="/">
              <Createelement_MT>
                   <Statement>
                        <TableName>
                             <table>XYZ</table>
                        <access>
                             <xsl:for-each select="Createelement_MT/Field">
                                  <xsl:variable name="field" select="@Name"></xsl:variable>
                                  <xsl:element name="{$field}">
                                  <xsl:value-of select="Value"></xsl:value-of>
                                  </xsl:element>
                             </xsl:for-each>
                        </access>
                        </TableName>
                   </Statement>
              </Createelement_MT>
         </xsl:template>
    </xsl:stylesheet>
    input xml
    <?xml version="1.0" encoding="UTF-8" ?>
    - <Createelement_MT>
    - <Field Name="A">
      <Value>1</Value>
      </Field>
    - <Field Name="B">
      <Value>1</Value>
      </Field>
      </Createelement_MT>
    output xml
    <?xml version="1.0" encoding="UTF-8" ?>
    - <Createelement_MT>
    - <Statement>
    - <TableName>
      <table>XYZ</table>
    - <access>
      <A>1</A>
      <B>1</B>
      </access>
      </TableName>
      </Statement>
      </Createelement_MT>
    One small request, if you think your question has been answered,could you please kindly, if possible, close this thread.
    regards
    Anupam

  • How to dynamically add field name in where clause of select query in web dynpro?

    Hello,
    Can any body tell me how i can use select query with dynamic wheere condition.
    i have a requirement like there are multiple input fields  and i want to select data from two database
    and condition may vary .

    Hi
    In the where clause you need to write like
    WHERE NAME LIKE 'DE%'
    Regards
    Sudheer

  • Creating dynamic form fields

    I am trying to create a form with an input box, but also want to be able to have a link below it to be able to add another input box on demand. Does anyone know where i can find an example of this, i searched on google but wasn't able to find anything that good.

    I tried the following code in a .cfm page and everytime i run it i just get the following error:
    Server Error
    The server encountered an internal error and was unable to complete your request.
    Application server is busy.  Either there are too many concurrent requests or the server still is starting up.
    But any other page that run works fine, this is the only that gives me this error.
    <html>
    <head>
    <title></title>
    <script language="javascript">
    fields = 0;
    function addInput() {
    if (fields != 10) {
    document.getElementById('text').innerHTML += "<input type='file' value='' /><br />";
    fields += 1;
    } else {
    document.getElementById('text').innerHTML += "<br />Only 10 upload fields allowed.";
    document.form.add.disabled=true;
    </script>
    </head>
    <body>
    <cfform name="form">
    <input type="button" onclick="addInput()" name="add" value="Add input field" />
    <div id="text">
    </div>
    </cfform>
    </body>
    </html>

Maybe you are looking for

  • Glad I'm not the only one...

    I seriously thought I was the only person on the planet who had the WORST PHONE EVER!!! And now that the warranty has passed, I'm pretty sure I'm SOL until June of 2013. After a few months, this phone just started to go downhill. Some things you can

  • Slidebar keeps changing sides and won't scroll up/down with my mouse wheel

    Ever since i just turned on my computer today, the slide bar went from the right to the left and the mouse wheel won't scroll up or down but it works on all other browsers just not firefox...

  • Joining of differnet Table.

    Hi, can any one suggest me on this requirement  for reporting for diffenent tables. how can i go head  below requirement like infoset or  i need to go for generic extaction for function module. 1>RBKP-BLDAT               Doc/Chq Date 2>RBKP-BELNR    

  • Common follow-up task for multiple lead transaction types

    Hi Gurus, Happy New Year. I am creating 3 lead transaction types as per the business requirement and i want to use common lead follow-up task for all three Lead transaction types.  My question over here is what are the problems if i use common follow

  • IPhone 3G loses calendar entries on sync

    I'm synching my Iphone 3G (software 2.1) over ITunes 8 with Outlook 2002 on a PC running XP. Here's the problem: it syncs fine when there's a new entry on either the phone or the desktop, but if there's are new entries on both then the entry on the p