ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 10th, 2009, 12:08 PM
electron_89 electron_89 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 146 electron_89 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 9 h 28 m 48 sec
Reputation Power: 4
Question Populating and updating a form from a TEXT FILE - stuck

Hi I am new to Coldfusion.

Goal:
1. Display pipe delimited data from a text file to a table
2. Create edit function for each record
3. Pass the selected record to a form **STUCK** HELP ME!
4. Write to the text file by submitting form.

I can do this with database but text files is a whole new thing for me. I'm stuck on populating the form... help...

Thanks.


Here's my code:

Code:
<!---file location--->
<cfset textfile = "/fullpath/data.txt">
<!---linefeed character and carriage return character--->
<cfset crlf = Chr(10) & Chr(13)>
<!---save variable at starting point --->
<cfset rowID = 0>
<!---text existence of a parameter, if doesnot exist, continue regardless--->
<cfparam name="edit" default="">

<!---Read file--->
<cffile action="read" variable="Message" file="#textfile#">	

<!--- Set each line in variable--->
<cfset line="#Message#">
<!--- Set array variable, delimiter--->
<cfset arr = ListToArray(line, '|', true)>
    
	<cfif edit EQ "yes"> 
    <h1>Employee Data</h1>
    <p><a href="./edit.cfm">Back to Edit Page list</a></p>
    <table>
        <form action="edit.cgi" method=post>       
            <tr>
            	<td>Code:</td>
            	<td><input type=text size=7 maxlength=7 name=code value="<cfoutput>#arr[1]#</cfoutput>"></td>
            </tr>
            <tr>
            	<td>Name:</td>
            	<td><input type=text size=50 maxlength=50 name=name value="<cfoutput>#arr[2]#</cfoutput>"></td>
            </tr>
            <tr>
            	<td>Title:</td>
            	<td><textarea rows=4 cols=50 name=objective wrap=soft><cfoutput>#arr[3]#</cfoutput></textarea></td></tr>
            <tr>
            	<td colspan="2" align="right"><input type=submit value="Submit Changes" name="Submit Changes"></td>
           </tr>
        </form>
    </table>   

	<cfelse>
    
    <!---Output the Table headings --->
    <h1>Employee Data - Edit Page</h1>
    
    <table border="1">
      <tr align="left" class="tableHeadingEdit">
        
		<th valign="top">Code</th>
        <th valign="top">Name</th>
        <th valign="top">Title</th>
      </tr>
     
    <!---Iterate, read the file data by line ending--->
    <cfloop index="message" file="#textfile#">	
    
		<!--- Count row --->
        <cfset rowID = rowID + 1>
        
        <!--- Set each line in variable --->
            <cfset list="#message#">
            
            <!--- Set array variable, delimiter--->
            <cfset arr = ListToArray(list, '|', true)>
    
            <!--- Set array names for each field --->
            <cfset fieldNameArray = ArrayNew(1)>
            <cfset fieldNameArray[1] = "code">	
            <cfset fieldNameArray[2] = "name">
            <cfset fieldNameArray[3] = "title">
            <cfset fieldNameArray[4] = "">
    
          <tr>  
            
            <!--- Set colID to start at 0 for count --->
            <cfset colID = 0>
        
            <!--- Loop through each "message" in cells for a row--->
			<cfloop from="1"  to="#arraylen(arr)#" index="i">
    
                <!--- Set colID to count in increments of 1 --->
                <cfset colID = colID + 1>        
                
                <!--- Output each iteration of delimited values in cells across all fields --->
                <cfoutput>
                    <td class="rowText" name="#fieldNameArray[colID]##rowID#">#arr[variables.i]#</td>            	
                </cfoutput>
                    
            </cfloop>
                        
            <!--- Edit buttons --->              
            <cfset arrURL = ListToArray(list, '|', true)>  
            <cfoutput>
                <td align="center"><a href="?edit=yes&code=#arrURL[1]#">edit</a></td>
            </cfoutput>
        
          </tr>
              
    </cfloop>
    </table><br/>
    
    </cfif>


Text file:
Code:
SOF|Steve|Software Engineer|
ADM|Mary|Administrator|

Last edited by electron_89 : September 10th, 2009 at 07:38 PM. Reason: To be more clear

Reply With Quote
  #2  
Old September 10th, 2009, 12:10 PM
electron_89 electron_89 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 146 electron_89 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 9 h 28 m 48 sec
Reputation Power: 4
It sort of works but only populates with the first record data only regardless of which record is clicked to edit so I have a problem with figuring out how to tell it to populate according what is selected...

Last edited by electron_89 : September 10th, 2009 at 12:31 PM.

Reply With Quote
  #3  
Old September 10th, 2009, 01:37 PM
Ebot's Avatar
Ebot Ebot is offline
Meatball Surgeon
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jul 2004
Location: Elbow deep in code
Posts: 1,965 Ebot User rank is General 1st Grade (Above 100000 Reputation Level)Ebot User rank is General 1st Grade (Above 100000 Reputation Level)Ebot User rank is General 1st Grade (Above 100000 Reputation Level)Ebot User rank is General 1st Grade (Above 100000 Reputation Level)Ebot User rank is General 1st Grade (Above 100000 Reputation Level)Ebot User rank is General 1st Grade (Above 100000 Reputation Level)Ebot User rank is General 1st Grade (Above 100000 Reputation Level)Ebot User rank is General 1st Grade (Above 100000 Reputation Level)Ebot User rank is General 1st Grade (Above 100000 Reputation Level)Ebot User rank is General 1st Grade (Above 100000 Reputation Level)Ebot User rank is General 1st Grade (Above 100000 Reputation Level)Ebot User rank is General 1st Grade (Above 100000 Reputation Level)Ebot User rank is General 1st Grade (Above 100000 Reputation Level)Ebot User rank is General 1st Grade (Above 100000 Reputation Level)Ebot User rank is General 1st Grade (Above 100000 Reputation Level)Ebot User rank is General 1st Grade (Above 100000 Reputation Level)  Folding Points: 83309 Folding Title: Advanced FolderFolding Points: 83309 Folding Title: Advanced FolderFolding Points: 83309 Folding Title: Advanced FolderFolding Points: 83309 Folding Title: Advanced FolderFolding Points: 83309 Folding Title: Advanced Folder
Time spent in forums: 2 Weeks 2 Days 13 h 53 m 52 sec
Reputation Power: 1070
When anyone gives me a text file that holds data (or any type of file for that matter) The first thing I do is dump it to a table and just use that instead.
__________________
Three gigs for the secretaries fair
Seven gigs for the system source
Nine gigs for the coders in smoky lairs
One disk to rule them all, one disk to bind them
One disk to hold the files, and in the darkness grind'em
---------------------------------------------------
It is by caffeine alone that I set my mind in motion.
It is by the beans of Java, that my thoughts acquire speed.
The hand acquire shakes; the shakes become a warning.
It is by caffeine alone that I set my mind in motion.

Reply With Quote
  #4  
Old September 10th, 2009, 02:03 PM
electron_89 electron_89 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 146 electron_89 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 9 h 28 m 48 sec
Reputation Power: 4
I understand. Believe me, I would if I could. However, I am purposely told to do it this way by the boss.

Reply With Quote
  #5  
Old September 10th, 2009, 06:08 PM
kiteless kiteless is offline
Moderator
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 4,271 kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 2 Weeks 6 h 31 m 50 sec
Reputation Power: 896
If you're on CF8 you can just loop over the file:

<cfloop file="c:\temp\simplefile.txt" index="line">
<cfoutput>#line#</cfoutput><br>
</cfloop>

Reply With Quote
  #6  
Old September 10th, 2009, 06:36 PM
electron_89 electron_89 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 146 electron_89 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 9 h 28 m 48 sec
Reputation Power: 4
Quote:
Originally Posted by kiteless
If you're on CF8 you can just loop over the file:

<cfloop file="c:\temp\simplefile.txt" index="line">
<cfoutput>#line#</cfoutput><br>
</cfloop>


That has been done as you can see in my code. I am stuck on populating a selected row to a form and writing that update form back to the text file...

Last edited by electron_89 : September 10th, 2009 at 07:22 PM.

Reply With Quote
  #7  
Old September 10th, 2009, 11:28 PM
kiteless kiteless is offline
Moderator
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 4,271 kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 2 Weeks 6 h 31 m 50 sec
Reputation Power: 896
Ah I just saw the CFFile in the first section of the code and assumed that was how you were doing it.

Can't you just pass the line number of the line being edited, and then use that on the edit screen to determine which line's data to populate the form with, and do the same when saving it so you know which line to update?

Reply With Quote
  #8  
Old September 11th, 2009, 04:57 PM
cfSearching cfSearching is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 28 cfSearching User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 48 m 46 sec
Reputation Power: 0
Quote:
Originally Posted by electron_89
I understand. Believe me, I would if I could. However, I am purposely told to do it this way by the boss.


Well, I hope they are not planning to "add" lines as well as "edit". That might produce some ... interesting results.

Reply With Quote
  #9  
Old September 11th, 2009, 08:23 PM
kiteless kiteless is offline
Moderator
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 4,271 kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level)kiteless User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 2 Weeks 6 h 31 m 50 sec
Reputation Power: 896
Not if lines are added at the end of the file. Deleting would be an issue though, if the file changed between the time the list was viewed and the edit was called.

The alternative is to pass some other unique identifier that the edit page can use to locate the correct line to edit.

Any way you cut this, using a text file as a data repository is an absolutely terrible idea.

Reply With Quote
  #10  
Old September 11th, 2009, 08:36 PM
cfSearching cfSearching is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 28 cfSearching User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 48 m 46 sec
Reputation Power: 0
Yes, you are right. I meant to say add/delete (ie full manipulation)

Quote:
Any way you cut this, using a text file as a data repository is an absolutely terrible idea.


Yep. I agree 100%.

Reply With Quote
  #11  
Old September 25th, 2009, 12:39 PM
electron_89 electron_89 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 146 electron_89 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 9 h 28 m 48 sec
Reputation Power: 4
well that doesn't solve my problem...

Reply With Quote
  #12  
Old September 25th, 2009, 12:57 PM
cfSearching cfSearching is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 28 cfSearching User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 48 m 46 sec
Reputation Power: 0
Quote:
Originally Posted by electron_89
well that doesn't solve my problem...


Did you look at the suggestions kiteless made in his last posts?

Like it or not, there is no avoiding the fact that this is a bad idea and you may run into further issues. But it is something you should be aware of, so you can at least try and mitigate the damage if you are stuck with this option.

Reply With Quote
  #13  
Old September 25th, 2009, 01:14 PM
electron_89 electron_89 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2006
Posts: 146 electron_89 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 9 h 28 m 48 sec
Reputation Power: 4
Thanks cfSearching. Yes I am aware. I am stuck with this option.

Please see my new thread: http://forums.devshed.com/coldfusion-development-84/text-file-to-2d-array-641319.html

Reply With Quote
  #14  
Old September 26th, 2009, 02:32 PM
cfSearching cfSearching is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 28 cfSearching User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 48 m 46 sec
Reputation Power: 0
Did you ever look at the last two comments kiteless made in this thread?

Quote:
Can't you just pass the line number of the line being edited, and then use that on the edit screen to determine which line's data to populate the form with, and do the same when saving it so you know which line to update?


Quote:
....Not if lines are added at the end of the file. Deleting would be an issue though, if the file changed between the time the list was viewed and the edit was called.

The alternative is to pass some other unique identifier that the edit page can use to locate the correct line to edit.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Text files, Arrays, Forms, editing, updating, and deleting


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek