Solved

Saving html to a file

Posted on 2000-02-17
24
174 Views
Last Modified: 2010-03-05
My web page contains a rather large form for a customer to fill out.  I am giving them the option to partially complete the form, save it to a server side unix file so they can reopen it and comlete it at a later time.  My question is this:  Is it possible to save the entire html page as a file to be opened again later?  The file would contain all of the original html plus any user supplied 'data' contained in the 'value' attributes of the input fields.
0
Comment
Question by:dxo
  • 7
  • 7
  • 6
  • +2
24 Comments
 
LVL 8

Expert Comment

by:jhurst
ID: 2533072
Not really.  In order to send the already completed information back to the server you are going to use a POST.  (I say this since the GET tends to be limited in how much data it can process).  Now, when you do thos POST you are going to get the field names and current values.  Unless you do something rather clever with an applet you will get only the data, not the form.

Certainly there is no way that you can do this with perl on the sever side.

I have an apllication that works very much like this.  I save my form template with things like:
<input type=text name=UserName value="$$UserName">

Then, when I need to re-display the previously partially filled form, I just copy it line by line, replacing all $$xxx with the apprpriate values from the last session.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2536708
i think this is very much possible. in fact, i can write a piece of code that can do this.

let me know if you need the same.
0
 
LVL 8

Expert Comment

by:jhurst
ID: 2536759
I would like to see that.  Post it please.  In fact, if it works, that is, if it allows, with no special features on the clients machine to send back a copy of the page, I will post a question just maneshr and give him/her the 100 points.
0
 

Author Comment

by:dxo
ID: 2542611
Adjusted points to 125
0
 

Author Comment

by:dxo
ID: 2542612
maneshr - If you could post your code for this I would appreciate it AND give you the points.  In fact, since you are offering raw code, I have increased the points to 125,


Thanks in advance

dxo
0
 
LVL 8

Expert Comment

by:jhurst
ID: 2543315
I do not believe that he can do it, sadly.  It would be nice wouldn't it.
0
 

Author Comment

by:dxo
ID: 2547541
jhurst - Looks like you were right, manesher doesn't seem to have the code.   The answer that you gave is an option that I was aware of and  was where I was headed when I got the idea to try to store the entire html as a file.  But, unfortunately it doesn't look possible.  Thanks for your comments anyway.

dxo
0
 

Author Comment

by:dxo
ID: 2547627
jhurst - Looks like you were right, manesher doesn't seem to have the code.   The answer that you gave is an option that I was aware of and  was where I was headed when I got the idea to try to store the entire html as a file.  But, unfortunately it doesn't look possible.  Thanks for your comments anyway.

dxo
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2548262
i was enjoying the long weekend :)

what the program does is accept params in the HTML form.
the user could enter all or some of the values.
in any case the values are save to a pre-defined file (you can add your own code to make that a random and unique filename)with | as the delimiter.

the next time the user goes to that form whatever values were entered last time will be shown.

so the user can continue from where he/she has left off.


here's the code

====================save_form.pl
#!/usr/local/bin/perl

use CGI;

$query=new CGI;

$user_file="/tmp/form_params";  ##  file where users prefs are stored

##  Assign default values to the form variables
my($first_nme,$last_nme,$sex,$age);
$age=0;

print "Content-type: text/html\n\n";
if ($query->param){

  $first_nme=$query->param('first_nme');
  $last_nme=$query->param('last_nme');
  $sex=$query->param('sex');
  $age=$query->param('age');

  $data=$first_nme."|".$last_nme."|".$sex."|".$age."\n";

  `rm $user_file 2> /dev/null`;
  open(MYFILE,"> $user_file") || die $!;
  print MYFILE $data;
  close(MYFILE);
  `chmod 777 $user_file`;


  print "<B>Values that you entered have been saved!!</B><br>\n";
}else{
  if (-e $user_file){   ##  Get the User previously entered values
    open(MYFILE,"$user_file") || die $!;
    ($first_nme,$last_nme,$sex,$age)=split(/\|/,<MYFILE>);  ##  Get the individ
ual values
    close(MYFILE);
  }

  ##  Print the HTML form
  print qq{
    <form action=$ENV{SCRIPT_NAME} method=post>
    First Name: <input type=text name=first_nme value=$first_nme><BR>
    Last Name: <input type=text name=last_nme value=$last_nme><BR>
  };

  if ($sex=~ /^M$/){
    print qq{
    <input type=radio name=sex value="M" checked>Male
    <input type=radio name=sex value="F">Female<br>
    };
  }elsif ($sex=~ /^F$/){
    print qq{
    <input type=radio name=sex value="M" checked>Male
    <input type=radio name=sex value="F">Female<br>
   };
  }else{
    print qq{
    <input type=radio name=sex value="M">Male
    <input type=radio name=sex value="F">Female<br>
    };
  }

  if ($age==0){
    print qq{
    <select name=age>
    <option selected value="0">Younger than 10
    <option value="1">Between 10 & 25
    <option value="2">Older than 25
    </select>
    };
  }elsif ($age==1){
    print qq{
    <select name=age>
    <option value="0">Younger than 10
    <option selected value="1">Between 10 & 25
    <option value="2">Older than 25
    </select>
    };
  }elsif ($age==2){
    print qq{
   <select name=age>
    <option value="0">Younger than 10
    <option value="1">Between 10 & 25
    <option selected value="2">Older than 25
    </select>
    };
  }

  print qq{
    <input type=submit>
    </form>
  };
}
0
 
LVL 8

Expert Comment

by:jhurst
ID: 2548288
Maneshr,

How exactly do you believe that this manages to capture the html?  I am not sure whether you really are confused here or just jerking our chains.

If the latter, I admit, you got me.  But April 1st is over a month away!
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2548343
did you run the script?? from what i understand, dxo wants to save the values of a html file to a file and let the user continue with the filling process at a later time.

let me know your interpretation of the problem.

i dont know about you, but frankly i have a lot of work to do than  "jerk chains".
0
 

Expert Comment

by:lorentg
ID: 2548372
dxo, it is not really fair to allow maneshr to steal the points from jhurst like this.  Maneshr's approach does not work.  It does not capture the html, largely because as jhurst said, it can not be done.

Now that jhurst has pointed out that it is not possible it is hardly fair to say that he should not get the points.  He answered the question BEFORE you said that you were realizing that you should do something else.

He gave you the correct answer, give him the points.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 16

Expert Comment

by:maneshr
ID: 2548392
lorentg,

when you say it does not work. what does the script do or not do?
what do you think the script should do?

let me know. i know its easy to make accusations but do so only when you have the necessary proof.
0
 

Author Comment

by:dxo
ID: 2550847
OK - Was I not clear in my original question?  Was I not clear in my last posting?  Am I speaking a foriegn language?
I'll explain one more time:
I was looking for a way to store the exact html so it could be opened in a browser just like any other html page.  To parse in variables as manesher is doing here is not what I am looking for.  I have an html page that has over 800 variables in it and I would rather not write the entire perl script addressing each variable individually as has been suggested.  Unfortunately, it looks like this is what I am going to have to do since what I am really try to do can't be done.  I hate waisting 125 points on a "you can't do that" answer but I guess given mt original question, "you can't do that" is the correct answer.  So, I am sorry manesher, I know you tried to help but i all fairness, jhurst came up with the correct answer first and I must give him the points.
Jhurst - please repost your answer so I can give you the points.  I hope there are no hard feelings here.  
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2551159
i would love to see jhurst's solution, since the example he has given above would work for text boxes only. i am assuming you have radion buttons, check boxes, select items too.

i still think that it is possible to do what you are looking for.
0
 
LVL 8

Accepted Solution

by:
jhurst earned 120 total points
ID: 2551527
As jhurst, I too, would love to see a solution.  I do not believe that there is a solution.  This is why my answer said that there is not.

There is no solution to this.  This is the answer.  Sadly.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2551603
"There is no solution to this"

how i wish that were true :-)
0
 

Expert Comment

by:lorentg
ID: 2551655
There is no solution that does what was requested.  The question was answered.  Maneshr, why do you keep claiming or implying that there is a solution but failing to provide one?

There was an answer from jhurst.  Even though it was correct you muddied the waters by suggesting this was not the case and caused dxo to reject it.  

The answer still is not disputed.  Only dxo says that he now does not want to do it this way.  He got an answer and should give the points.

If you have a solution Maneshr, post it.  Put up or shut up.
0
 
LVL 16

Expert Comment

by:maneshr
ID: 2551763
lorentg,

what's your problem? let dxo decide whom to give points to. are you a rep for jhurst? do you get paid for canvassing for him?

this discussion was pretty decent till such time you decided to pop-in.
i think jhurst, dxo and myself were having a good discussion. keep you opinions to yourself & dont waste my time.




0
 

Expert Comment

by:lorentg
ID: 2552186
There is no solution that does what was requested.  The question was answered.  Maneshr, why do you keep claiming or implying that there is a solution but failing to provide one?

There was an answer from jhurst.  Even though it was correct you muddied the waters by suggesting this was not the case and caused dxo to reject it.  

The answer still is not disputed.  Only dxo says that he now does not want to do it this way.  He got an answer and should give the points.

If you have a solution Maneshr, post it.  Put up or shut up.
0
 
LVL 8

Expert Comment

by:jhurst
ID: 2552207
My thanks to lorentg but I really do not need this.

dxo has decided, after an answer was posted by me that he no longer wants an answer and will not give points.  I do not really think that this is playing the game fairly, but so what?

maneshr seems to feel that he has a solution.  We have yet to see it.  Not only do I believe that he should get the points from dxo if he had a solution, I offered some additional points myself.

However he can not.

At this point.  Since dxo has decided not to allocate points and since maneshr can not provide a solution I believe that dxo should just delete the question and make this whole mess go away.



0
 
LVL 3

Expert Comment

by:darinw
ID: 2552218
lorentg -- If you continue to lock questions to harrass the customers/experts I will close your account.

dxo, please reject the proposed answer and select the appropriate expert's comment as the answer.

darinw
Customer Service
0
 

Author Comment

by:dxo
ID: 2552231
I am accepting jhurst's first answer which I have previously rejected because I thought manesher was going to deliver. He didn't so the points go to jhurst.
0
 
LVL 8

Expert Comment

by:jhurst
ID: 2552234
My thanks to lorentg but I really do not need this.

dxo has decided, after an answer was posted by me that he no longer wants an answer and will not give points.  I do not really think that this is playing the game fairly, but so what?

maneshr seems to feel that he has a solution.  We have yet to see it.  Not only do I believe that he should get the points from dxo if he had a solution, I offered some additional points myself.

However he can not.

At this point.  Since dxo has decided not to allocate points and since maneshr can not provide a solution I believe that dxo should just delete the question and make this whole mess go away.



0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Uploading Binary Data using Perl 5 71
compress files in RAR using perl 13 74
Perl Awk Need Help 3 94
Perl File::Find alternative 1 27
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now