Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save copy of forms

Status
Not open for further replies.

petenyce105

Programmer
Feb 3, 2004
12
US
i have aform that gets submitted to a mysql database. now is their a way to save a copy of this form like a history of submissions for the user to see?
 
Personally I'd create an audit table and a seperate page that accesses the audit table to give the user the select information you're talking about. Audit logs are a great way to debug problems also if you can't reproduce an error that your users have created. I tend to throw as much info as possible to audit logs just to make it that much more clear what the user was doing.

-kaht

banghead.gif
 
I agree with kaht. However, if you still want a JavaScript solution, try this:

<html>
<head>
<script>
function formClone(formName){
var f=document[formName],x=[];
for(var i=0;i<f.elements.length;i++){
switch(f.elements.type){
case &quot;select-one&quot;:
x=f.elements.selectedIndex;
break;
case &quot;select-multiple&quot;:
var y=[];
for(var j=0;j<f.elements.length;j++){
y[j]=f.elements[j].selected;
}
x=y;
break;
case &quot;radio&quot;:
x=f.elements.checked;
break;
case &quot;checkbox&quot;:
x=f.elements.checked;
break;
default:
x=f.elements.value;
}
}
this.formName=formName;
this.elements=x;
this.recallClone=recallClone;
}
function recallClone(){
for(var i=0;i<f.elements.length;i++){
switch(f.elements.type){
case &quot;select-one&quot;:
f.elements.selectedIndex=this.elements;
break;
case &quot;select-multiple&quot;:
var y=[];
for(var j=0;j<f.elements.length;j++){
f.elements[j].selected=this.elements[j];
}
break;
case &quot;radio&quot;:
f.elements.checked=this.elements;
break;
case &quot;checkbox&quot;:
f.elements.checked=this.elements;
break;
default:
f.elements.value=this.elements;
}
}
}

var formClones=[];
</script>
</head>
<body>
<form name=&quot;f&quot;>
<input type=&quot;text&quot; name=&quot;t&quot; value=&quot;1&quot;><br>

<select name=&quot;s&quot;>
<option value=&quot;&quot;>a
<option value=&quot;2&quot; selected>b
</select><br>

<select name=&quot;s&quot; multiple>
<option value=&quot;&quot;>a
<option value=&quot;3&quot; selected>b
<option value=&quot;3&quot; selected>c
</select><br>

<input type=&quot;radio&quot; name=&quot;r&quot; value=&quot;0&quot;>
<input type=&quot;radio&quot; name=&quot;r&quot; value=&quot;0&quot;>
<input type=&quot;radio&quot; name=&quot;r&quot; value=&quot;4&quot; checked><br>

<input type=&quot;checkbox&quot; name=&quot;c&quot; value=&quot;0&quot;>
<input type=&quot;checkbox&quot; name=&quot;c&quot; value=&quot;0&quot;>
<input type=&quot;checkbox&quot; name=&quot;c&quot; value=&quot;5&quot; checked><br>

<br><br>
<input type=&quot;button&quot; onclick=&quot;formClones[formClones.length]=new formClone('f');this.form.cloneList[this.form.cloneList.length]=new Option(formClones.length,formClones.length)&quot; value=&quot;Save Form&quot;>

<select name=&quot;cloneList&quot;></select><input type=&quot;button&quot; onclick=&quot;if(this.form.cloneList.selectedIndex>-1){formClones[this.form.cloneList.selectedIndex].recallClone()}&quot; value=&quot;Recall Clone&quot;>
</form>

Adam
while(ignorance==true){perpetuate(violence,fear,hatred);life=life-1};
 
If you want to store the form for longer than the user is at the page, you should add it to a table in your database.

Adam
while(ignorance==true){perpetuate(violence,fear,hatred);life=life-1};
 
It would make more sense to store it in a database and retreive it into your database. I'm sure you could write a script to write all the data to an external .html file, but storing data is what databases are for so it would make more sense to do it that way.

-kaht

banghead.gif
 
I'm sure you could write a script to write all the data to an external .html file -- I am not so sure I have as much confidence as you do, kaht (based on the question and the followup replies to the question).

I think the answer to this is rather straight forward... No. You cannot &quot;store on a web page&quot; nor create a &quot;history of submissions&quot; in the way you have in mind. You need a database and a means for the user to identify themselves to the database (login process) assuming it is multi-user.

Sometimes we need to be brutally honest about the real-world applications we are developing. If this is a functional requirement for your application, then you will need to find a way to achieve it using *some* kind of back-end database (whether that is a txt file, access file, or more traditional database - sql, mysql etc).

Jeff
 
well i have it stored in a mysql database, but is their a way to show online what forms have been submitted instead of me doing it manually. So if the user submitts 5 forms they can check a web page and see copys of those forms they submitted?
 
You will have to code the web page that will return a list of forms that that specific user has submitted. Your page will query the mysql database and return a list of results that match your query.

Jeff
 
I think I'm starting to get this now.... you probably haven't done any web database accessing before and are wanting to get some tips on how it's done. Sorry, I assumed that the data got put in the database thru a web application in the first place.

To access data from a mysql database you are gonna have to run server side scripts to generate your HTML. This is done using programs such as ASP, PHP, JSP, etc. (I use ASP) You might wanna start posting on one of those forums, but first you need to see what server side language you can use on your server.

If I'm completely off base with this reply, I'm sorry. I didn't mean to insult your intelligence or anything. If you already know about all the stuff I posted above and still have problems, then perhaps you could provide us with what code you have so far and we can help you build off it.

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top