[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do i update/add new records via an Iframe joined with the main page? **Urgent** Please Help!

Posted on 2006-04-06
4
Medium Priority
?
173 Views
Last Modified: 2013-12-24
Hello Experts,

My second question as the first was not answered, may be because it was too long.

Ok

I am trying to add new and update records in two different tables. Currently the data from the parent table is displayed on the page whereas the child tables's data is displayed using an iframe.

This makes it tricky to add a new record when both these sections are connected via a primary key:ProductCode.

I am strugling with this and need your help in implementing two different functionalities on this page.

1. Adding new records

Where the parent and child tables will both have a new record entered.

2. Updating existing records

where the record currently displayed on the form can be updated.


Ok this is the scenario i am trying yo make it work.

1. User clicks the Add New product button. Result: all the fields on form would become blank so the user can add new info. This includes the iframe. Once the user has finished entering the data, he/she would click on submit changes and then the data would be passed through to the savechanges.cfm file.

2. User clicks on update product details button. Result a new row is added within the iframe data so that the user can add new data for the particular product being displayed on screen. Once the user has finished entering the new data, he/she would then click on submit changes and then the data would be passed through to a savechanges.cfm file.


I am not sure how to go about this. I have managed to display the data but i really need to ass this functionality of adding and editing data.

All help and ideas on how to achieve this will be highly appreciated.

Thanks,

Nav
0
Comment
Question by:Navgod
  • 2
4 Comments
 
LVL 10

Expert Comment

by:rob_lorentz
ID: 16395297
on the main page, when you open the iframe, pass the current product id to the iFrame's page.

example:

<cfoutput query="getProd">
   product: #getProd.productName#

    <iframe name="prodDetails.cfm?prodId=#getProd.id#">
    </iframe>
</cfoutput>

Then your 'child' page knows what product you are working on.

This is a general idea how this.
0
 
LVL 9

Accepted Solution

by:
digicidal earned 1500 total points
ID: 16399665
Since you are already going to be getting a page refresh with a form submission why not just eliminate the iframe for the child information on the add/update.  That way you'll have less problems with validation etc... say the page has three states which are passed by a URL parameter (1=view, 2=add, 3=edit).
Example page:

<cfif IsDefined("FORM.submit")>
   <cfif IsDefined("FORM.recordID") AND IsNumeric(FORM.recordID)>
       ... Place processing code & query(s) for updating the edited record of the passed recordID value ...
       <cfelse>
       ... Place processing code & query(s) inserting a new record based on passed values ...
   </cfif>
</cfif>
<cfparam name="url.view" default="1">
<cfswitch expression="#url.view#">
<cfcase value="1">
... Your current display page code here ...
</cfcase>
<cfcase value="2">
... Single form with all of the information required for an insert ...
</cfcase>
<cfcase value="3">
... Copy of the add form except with a hidden recordID field and values for each of the corresponding inputs ...
</cfcase>
</cfswitch>

Since the form processing occurs before each page version's display area, updates will be reflected in the view page.  Both forms in this case would have an action="myPageName.cfm?view=1" so that after a form submission they would return to the display version of the page.

Not sure if that's what you want, but it would work for you.  It's difficult to write an example based on your description (or more specifically the issues that might come up in handling a dual-page submission - iframe).  That solution would need some javascript behind it I think, but I could be wrong about that.  I haven't used iframes in this way on a form, but from what I know, I think they are dealt with in the browser as a totally separate page layer.
0
 

Author Comment

by:Navgod
ID: 16400213
Hi!

The reason i am having the iframe is because i am upsizing a previous access database, and am under strict instructions to make the new design look similar to the forms designed in access.

This is the code i have so far.

//index.cfm

<body>
<p>
  <cfparam name="url.a" default="menu">
  <cfparam name="url.search" default="">
  <cfparam name="startrow" default="1">
 
 
</p>
 
    <form name="search" action="index.cfm?a=horsham_exports&search=yes" method="post">
    <table width="720" cellpadding="0" cellspacing="0" align="center"><tr><td align="center"><h3>Horsham Exports</h2></td></tr></table>
    <cfquery name="get_products" datasource="dt446">
      select * from tblhorsham_exports order by description asc
    </cfquery>

    <cfif url.search is "yes">
      <cfoutput query="get_products">
        <cfparam name="count" default="1">
        <cfif form.productcode eq #productcode#>
          <cfset startrow = #count#>
        <cfelse>
          <cfset count = count + 1>
        </cfif>
        <cfset PRODUCTCODE = #FORM.PRODUCTCODE#>
      </cfoutput>
    </cfif>

    <!--- Set the default startrow to 1 if a value was not passed. --->
    <!--- Determine whether or not to show the previous or next links. --->
    <cfparam name = "StartRow" default = "1">
    <!--- Set the value of endrow to the maxrows + startrow - 1 --->
    <cfset EndRow = StartRow + 1 - 1>
    <!--- If the end row is greater than the recordcount, determine how many records are left. --->

    <cfif EndRow GTE get_products.RecordCount>
      <cfset EndRow = get_products.RecordCount>
      <cfset Next = false>
      <!--- Otherwise, set Next to true and determine the next set of records. --->
    <cfelse>
      <cfset Next = true>
      <cfif EndRow + 1 GT get_products.RecordCount>
        <cfset NextNum = get_products.RecordCount - EndRow>
      <cfelse>
        <cfset NextNum =  1>
      </cfif>
     <cfset NextStart = EndRow + 1>
    </cfif>
    <!--- If StartRow is 1, set Previous to false. --->
    <cfif StartRow IS 1>
      <cfset Previous = false>
    <!--- Othewise, determine the previous set of records. --->
    <cfelse>
      <cfset Previous = true>
      <cfset PreviousStart = StartRow - 1>
    </cfif>
    <!--- Determine how many pages will be displayed. --->
    <cfset NumPages = Ceiling(get_products.RecordCount / 1)>
    <cfparam name = "PageNum" default = "1">

    <cfoutput query="get_products" maxrows="1" startrow="#STARTROW#">

    <cfquery  name="get_shipping" datasource="dt446">
      select * from tblhorsham_exports_pack_details where productcode = '#productcode#'
    </cfquery>

    <table width="720" cellspacing="1" cellpadding="4" bgcolor="cccccc" align="center">
      <tr bgcolor="19569B">
        <td colspan="8" bgcolor="19569B" class="large_white">PRODUCT DETAILS</td>
      </tr>
      <tr bgcolor="ffffff">
        <td width="100">Product Code:</td>
        <td width="100">#productcode#</td>
        <td width="70">Type:</td>
        <td width="70">#type#</td>
        <td width="90">Source:</td>
        <td width="50">#source#</td>
        <td colspan="2" rowspan="3" align="center"><img src="images/packaging.jpg" border="0"></td>
      </tr>
      <tr bgcolor="ffffff">
        <td>Packaging Line:</td>
        <td>#packagingline#</td>
        <td>Pack Size:</td>
        <td>#packsize#</td>
        <td>Destination:</td>
        <td>#destination#</td>
      </tr>
      <tr bgcolor="ffffff">
        <td>Description:</td>
        <td colspan="5">#description#</td>
      </tr>
      </table>
      <br>
      <cfset session.startrow = #startrow#>
      <cfset session.productcode = #productcode#>
    </cfoutput>      

    <table width="720" cellspacing="1" cellpadding="3" bgcolor="cccccc" align="center">
        <tr bgcolor="19569B">
          <td class="large_white">PACKAGING INFORMATION -  <font color="red">Weight (grms/Pack)</font></td>
        </tr>
      <tr>
          <td><iframe align="left" marginheight="3" marginwidth="3" height="100" width="100%" frameborder="0" scrolling="yes" name="packaging" src="iframe.cfm"></iframe></td>
      </tr>
      </table>
    <TABLE width="720" BORDER = "0" cellspacing="1" cellpadding="3" bgcolor="cccccc" align="center">
      <TR bgcolor="#19569B" style="color:#FFFFFF;font-weight:bold">
        <TD width="141" align="center">
          <!--- If Next is true, display the previous link. --->
          <CFOUTPUT><A HREF = "index.cfm?StartRow=1&a=horsham_exports" style="color:##FFFFFF">&lt;&lt; First Record &nbsp;</A></CFOUTPUT></TD>
        <TD width="140" style="color:##FFFFFF" align="center">
          <!--- If Previous is true, display the previous link. --->
          <cfif Previous>
            <CFOUTPUT><A HREF = "index.cfm?StartRow=#PreviousStart#&PageNum=#DecrementValue(PageNum)#&a=horsham_exports" style="color:##FFFFFF">&lt;&lt;&nbsp;Previous</A></CFOUTPUT>
          <cfelse>
            <A HREF = "##" style="color:##FFFFFF" onClick="alert('This is the first record')">&lt;&lt;&nbsp;Previous</A>
          </cfif>
        </TD>
        <TD width="178" align="center">
        <!--- If Next is true, display the previous link. --->
          <cfif Next>
            <CFOUTPUT>
              <A HREF = "index.cfm?StartRow=#NextStart#&PageNum=#IncrementValue(PageNum)#&a=horsham_exports" style="color:##FFFFFF">Next&nbsp;&gt;&gt;</A>
            </CFOUTPUT>
          <cfelse>
            <A HREF = "##" style="color:##FFFFFF" onClick="alert('This is the last record')">Next Record</A>
          </cfif>
        </TD>
        <TD width="112" align="center">
          <CFOUTPUT>
            <A HREF = "index.cfm?StartRow=#get_products.recordcount#&a=horsham_exports" style="color:##FFFFFF">Last Record&nbsp;&gt;&gt;</A>            </CFOUTPUT>
        </TD>
      </TR>
    </TABLE>
   
    <table width="467" height="40" border = "0" align="center" cellpadding="3" cellspacing="1" bgcolor="cccccc">
      <tr bgcolor="#19569B" style="color:#FFFFFF;font-weight:bold">
        <td width="141" align="center" bgcolor="#FFFFFF" style="color:##FFFFFF"><label>
          <input name="Add New" type="submit" id="Add New" value="Add New Product" />
        </label>        </td>
        <td width="179" align="center" bgcolor="#FFFFFF"><label>
          <input name="Update" type="submit" id="Update" value="Update Product Details" />
        </label></td>
        <td width="125" align="center" bgcolor="#FFFFFF"><label>
          <input type="submit" name="Submit3" value="Submit Changes" />
        </label></td>
      </tr>
    </table>
    <table width="720" cellpadding="3" align="center">
      <tr>
        <td width="285" valign="top">
          <table width="100%" cellspacing="0" cellpadding="3" bgcolor="cccccc" align="center">
            <tr bgcolor="ffffff">
              <td valign="top"><a href="#" onClick="alert('This form is used for entering all for products being exported outside the U.K. from the Horsham Site.')" class="link1">For More Information - Click Here</a></td>
            </tr>
            <tr bgcolor="ffffff">
              <td valign="bottom" height="25"><img src="images/logo.jpg" border="0"></td>
            </tr>
          </table>
        </td>
        <td width="285" valign="top">
          <table width="100%" cellspacing="1" cellpadding="3" bgcolor="cccccc">
                <tr class="large_white" bgcolor="19569B">
                    <td colspan="2">PRODUCT SEARCH</td>
                  </tr>
                <tr bgcolor="ffffff">
                    <td width="100">Product Code:</td>
                    <td><input type="text" class="cellbox"  name="productcode" size="15">&nbsp;<input type="submit" value="Go"></td>
                  </tr>
              </table>
            </td>
        <td width="150" valign="top">
          <table width="100%" cellspacing="1" cellpadding="3" bgcolor="cccccc">
                <tr class="large_white" bgcolor="19569B">
                    <td colspan="2">OPTIONS</td>
                  </tr>
                <tr bgcolor="ffffff">
                    <td width="65" align="center"><input type="button" onClick="javascript:self.location='horsham.cfm?a=menu'" value="Menu"></td>
                    <td width="74" align="center"><input type="button" onClick="javascript:self.location='horsham.cfm?a=menu'"  value="Close"></td>
                  </tr>
              </table>
            </td>
      </tr>
    </table>
  </form>
 
</body>
</html>



//Iframe.cfm

 <cfquery  name="get_shipping" datasource="dt446">
    select * from tblhorsham_exports_pack_details where productcode = '#session.productcode#'
  </cfquery>
<cfoutput>
  <table align="center" width="3000" cellspacing="1" cellpadding="3" bgcolor="cccccc">
    <tr bgcolor="f6f6f6">
      <td>Quantity</td>
      <td>Date_From</td>
      <td>Date_To</td>
      <td>HMP_Securitainer</td>
      <td>HMP_Cap</td>
      <td>HMP_Plastic_Bottle</td>
      <td>HMP_Foil</td>
      <td>HMP_Blisters_PVC</td>
      <td>HMP_Tube_Plastic</td>
      <td>HMP_Glass_Bottle</td>
      <td>HMS_Plastic_Tray</td>
      <td>HMS_Carton</td>
      <td>HMT_Overwrap</td>
      <td>HMT_Cardboard_Outer</td>
      <td>IMP_Securitainer</td>
      <td>IMP_Metal_Cap</td>
      <td>IMP_Cap</td>
      <td>IMP_Plastic_Bottle</td>
      <td>IMP_ALU_Blister</td>
      <td>IMP_Tubes_Plastic</td>
      <td>IMP_GLass_Bottle</td>
      <td>IMP_ALU_Strip</td>
      <td>IMP_Tube_Alu</td>
      <td>IMS_Plastic_tray</td>
      <td>IMS_Carton</td>
      <td>IMT_Overwrap</td>
      <td>IMT_Cardboard_Outer</td>
      <td>IMT_Plastic</td>
      <td>IMT_Cardboard</td>
      <td>IMT_Metal</td>
      <td>IMT_Wood</td>
    </tr>
  <cfloop query="get_shipping">
    <tr class="small_black" bgcolor="<cfif currentrow mod 2>##FFFFFF<cfelse>##E6E6E6</cfif>">
      <td>#Quantity#</td>
      <td width="80">#left(Date_From,10)#</td>
      <td width="80">#left(Date_To,10)#</td>
      <td>#HMP_Securitainer#</td>
      <td>#HMP_Cap#</td>
      <td>#HMP_Plastic_Bottle#</td>
      <td>#HMP_Foil#</td>
      <td>#HMP_Blisters_PVC#</td>
      <td>#HMP_Tube_Plastic#</td>
      <td>#HMP_Glass_Bottle#</td>
      <td>#HMS_Plastic_Tray#</td>
      <td>#HMS_Carton#</td>
      <td>#HMT_Overwrap#</td>
      <td>#HMT_Cardboard_Outer#</td>
      <td>#IMP_Securitainer#</td>
      <td>#IMP_Metal_Cap#</td>
      <td>#IMP_Cap#</td>
      <td>#IMP_Plastic_Bottle#</td>
      <td>#IMP_ALU_Blister#</td>
      <td>#IMP_Tubes_Plastic#</td>
      <td>#IMP_GLass_Bottle#</td>
      <td>#IMP_ALU_Strip#</td>
      <td>#IMP_Tube_Alu#</td>
      <td>#IMS_Plastic_tray#</td>
      <td>#IMS_Carton#</td>
      <td>#IMT_Overwrap#</td>
      <td>#IMT_Cardboard_Outer#</td>
      <td>#IMT_Plastic#</td>
      <td>#IMT_Cardboard#</td>
      <td>#IMT_Metal#</td>
      <td>#IMT_Wood#</td>
    </tr>  
   </cfloop>
  </table>
</cfoutput>


I expect to filter the data through to a savechanges.cfm file which later inserts the data into the tables.

I am not sure how i can make the buttons work on the page to serve their task.

I am doing as part of a project at college, thus the urgency.

Thanks for all your help!

Nav
0
 
LVL 9

Expert Comment

by:digicidal
ID: 16402225
Hmmm I'll take a look at your code, but hopefully someone else will step in on this.  There is going to have to be some javascript functions to communicate between the parent and child areas, and then some display changes based on what is happening in each (view/edit/add).  It definitely doesn't look to me like it's an easy solution, but maybe someone else has more experience with this kind of iframe interaction.
0

Featured Post

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.

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month18 days, 10 hours left to enroll

834 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