[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

Multiple Requests on One Form...

I'm not even sure how to ask the question, but here is what I am trying to do.  I  have a form which requests time off.  The current form allows for one date per request.  What I am trying to do is create the form to allow for multiple days so when the user submits the request, whether they request one day or 5 days it populates the dbase once or 5 times (whichever is the case) so that the requests may be processed.  Upon submit, the request submits to an Access dbase.

The form currently looks something like this:

<CFFORM NAME="timeoff" ACTION="post.cfm" METHOD="POST">
<table cellspacing="2" cellpadding="2" border="2" bgcolor="#333333" bordercolor="#6699CC">
<tr bordercolor="#333333">
    <td colspan="2" width="200" nowrap class="normalsilver">&nbsp;&nbsp;&nbsp;<b>Your Name:</b></td>
    <td colspan="2" width="300" nowrap class="normalsilver">
      <cfoutput>
            <select name="#EmployeeID#">#SortName#</select>
      </cfoutput>
     </td>
</tr>
<tr bordercolor="#333333">
    <td colspan="2" width="200" nowrap class="normalsilver">&nbsp;&nbsp;&nbsp;<b>Date Requested:</b></td>
    <td nowrap class="normalsilver">
            <INPUT TYPE="text" NAME="DateRequested" SIZE="14" value="">
            <a onclick="javascript: popUpCalendar(this, DateRequested, 'mm/dd/yyyy', -1, -1);" onMouseOver="style.cursor='hand';" onMouseOut="style.cursor='default';">
          <img src="../images/popupcalendar/calendar.gif" align="absmiddle" border="0">
            </a>
      </td>
    <td class="tinywhite">Now accepting requests prior to and including <b><CFOUTPUT>#DateFormat(CreateODBCDate(now()+90), "MM/DD/YYYY")#</CFOUTPUT></b></td>
</tr>
<tr bordercolor="#333333">
    <td colspan="2" width="200" nowrap class="normalsilver">&nbsp;&nbsp;&nbsp;<b>Reason:</b></td>
    <td colspan="2" width="300" nowrap class="normalsilver">
            <select name="reason">
                        <option value="">
                  <cfoutput query="qsel_reasons">
                        <option value="#reason#">#reason_name#
                  </cfoutput>
            </select>
      </td>
</tr>
<tr bordercolor="#333333">
    <td colspan="2" width="200" nowrap class="normalsilver">&nbsp;&nbsp;&nbsp;<b>Shift:</b></td>
    <td colspan="2" width="300" nowrap class="normalsilver">
            <select name="shift">
                  <option value=""></option>
                  <option value="1st">1st Shift</option>
                  <option value="2nd">2nd Shift</option>
            </SELECT>
      </td>
</tr>
<tr bordercolor="#333333">
    <td colspan="2" width="200" nowrap class="normalsilver">&nbsp;&nbsp;&nbsp;<b>All Day:</b></td>
    <td width="75" nowrap class="normalsilver">
            <b>Yes</b><INPUT onClick="MM_showHideLayers('Layer1','','hide')" type="radio" value="Yes" name="allday" checked>
      </td>
    <td width="75" nowrap class="normalsilver">
            <b>No</b><INPUT onClick="MM_showHideLayers('Layer1','','show')" type="radio" value="No" name="allday">
      </td>
</tr>
<tr bordercolor="#333333">
    <td colspan="4" width="500" height="60" nowrap class="normalsilver">
      <!-- The Values for teh textBoxes can be decided at run time / predefined using query -->
    <DIV id="Layer1" style="Z-INDEX: 1; LEFT: 306px; VISIBILITY: hidden; WIDTH: 200px; POSITION: absolute; TOP: 471px; HEIGHT: 50px">
         <TABLE cellSpacing="0" cellPadding="0" border="0" bgcolor="#333333">
              <TBODY>
                   <TR>
    <td width="100" nowrap class="normalsilver"><b>Time Start:</b></td>
    <td width="200" nowrap class="normalsilver">
      <select name="timestart">
            <option value="">
            <cfoutput query="qsel_time">
                  <option value="#military#">#regular#
            </cfoutput>
      </select>      
      </td>
                   </TR>
              </TBODY>
         </TABLE>
         <TABLE cellSpacing="0" cellPadding="0" border="0" bgcolor="#333333">
              <TBODY>
                   <TR>
    <td width="100" nowrap class="normalsilver"><b>Duration:</b></td>
    <td width="200" nowrap class="normalsilver">
      <select name="duration">
            <option value="">
            <cfoutput query="qsel_duration">
                  <option value="#duration#">#actual#
            </cfoutput>
      </select>            
      </td>
                   </TR>
              </TBODY>
         </TABLE>
    </DIV>
      </td>
</tr>
<tr bordercolor="#333333">
    <td colspan="4" width="500" height="50" nowrap class="normalsilver">
      <input type="hidden" name="SubmitTime" value="<cfoutput>#CreateODBCDateTime(DateAdd("h",3, Now()))#</cfoutput>">
      <DIV align="center">
            <INPUT type="submit" value="Submit" class="subheadblue">&nbsp;&nbsp;
            <INPUT type="Reset" value="Clear Form" class="subheadblue">
      </div>
      </td>
</tr>
</table>
</CFFORM>

Any suggestions on how I accomplish this?
0
Lee R Liddick Jr
Asked:
Lee R Liddick Jr
  • 2
1 Solution
 
smaglio81Commented:
right now you have a text input field for the date. You can change that to a select input field and populate it with a number of upcoming dates. Then you can allow the user to select multiple entries within the select input field. An example might be,

<cfset sDate = now() />
You may select a range of dates by selecting the first date and shift-clicking the final date:<br />
<select multiple="multiple" size="10" name="dateRequested">

      <!--- loop over the next 3 months worth of dates --->
      <cfloop index="i" from="0" to="90">
      
            <!--- generate a date --->
            <cfset loopDate = DateFormat( DateAdd( "d", i, sDate ), "mm/dd/yyyy" ) />
            
            <!--- add the date to the list --->
            <cfoutput>
                  <option value="#loopDate#">#loopDate#</option>
            </cfoutput>
      </cfloop>
</select>

Then you would be presented with a list of dates within your action page, "post.cfm". You would need to rewrite the query to loop over the list of dates and perform an insert sql query for each date selected.

HTH,

Steven
0
 
Lee R Liddick JrReporting AnalystAuthor Commented:
Wow...I forgot I posted this question.  Steven...you mentioned that the shift-clicking on the dates will populate multiple dates in the field...but does the cntrl-click work as well if they want to select say 11/26 and 11/29?

Also...I'm not sure how I would rewrite the query to loop over the dates and do an insert into the table for each date selected.  Is there a site anywhere you would deem helpful on this topic?

Thanks again...and my apologies for the delay...

lrl
0
 
smaglio81Commented:
Yeah, you can use Control-Click to select a group of individual dates.

When the form is submitted, the action page will recieve the data within the variable form.dateRequested as a comma deliminated list of dates. In order to look through the dates, you can use another cfloop.

<cfloop index="date" list="#form.dateRequested#">

      <cfquery datasource="#dsn#">
           INSERT INTO <tblName>
                   ( personID, submittedDate, dateRequested )
           VALUES (
                    <cfqueryparam cfsqltype="cf_sql_int" value="#form.personID#" />,
                    getDate(),
                    <cfqueryparam cfsqltype="cf_sql_date" value="#date#" />
            )
      </cfquery>

</cfloop>


Except you would change the column names and values entered to be what works with your database.

I don't really know of a good way in Coldfusion to send over a list of entries into a database. So, for now I use repetitions insert statements to get the job done.

Steven
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now