PDA

View Full Version : passing variables


nvysel24
02-19-2010, 06:23 PM
Ok well ill give you the general outline.
I have a very basic html webpage with a form and 2 text fields and a submit button in a form which is below

<form method="post">

<input type="text" name="fname" size="25" maxlength="1" value="Enter your first initial"><br>
<input type="text" name="lname" size="25" maxlength="15" value="Enter your last name here"><br>
</form>
<input type="submit" name="usercreate" value="Create User" onClick="parent.location='writetofile.asp'">


i need help figuring out how to take the variables that the user jus inputted into the text field and put them into the asp script i created which is still in progress which is below

<html>
<body>
<%
createaccount="[Account]"

Set fs = CreateObject("Scripting.FileSystemObject")

Set wfile = fs.CreateTextFile("C:\test.ini", True)
wfile.Write (createaccount)

wfile.close
Set wfile=nothing
Set fs=nothing


Response.Redirect "creation.html"
%>
</body>
</html>


what i think somthing along the lines of editing the asp script by editing the line

Set wfile = fs.CreateTextFile("C:\test.ini", True)

to

Set wfile = fs.CreateTextFile("C:\"+somthing.fname+somehting.lname+".ini", True)


am i anywhere close?
or if im not could you lead me in the right direction or fix the code maybe
Thanks :D

angst
02-19-2010, 06:53 PM
ok, first of all, you have no action in your <form> tag. like action='SomePage.asp',

on that page ( when setup ), you could retrieve the input data using:

response.write request("fname")
response.write request("lname")


also your submit button is out side of the form tags.

And...then in your submit button you have this: onClick="parent.location='writetofile.asp'", this is a redirect and wont post any data.

And another; ("C:\"+somthing.fname+somehting.lname+".ini", True), that looks more like javascript syntax to me. asp uses & ( ampersand ) instead of plus signs.


rewrite!

the form:


<form method="post" action='writetofile.asp'>
<input type="text" name="fname" size="25" maxlength="1" value="Enter your first initial"><br>
<input type="text" name="lname" size="25" maxlength="15" value="Enter your last name here"><br>
<input type="submit" name="usercreate" value="Create User">
</form>



and the writetofile page:

<html>
<body>
<%
fname = request.post("fname")
lname = request.post("lname")

createaccount = fname & " " & lname

Set fs = CreateObject("Scripting.FileSystemObject")

Set wfile = fs.CreateTextFile("C:\test.ini", True)
wfile.Write (createaccount)

wfile.close
Set wfile=nothing
Set fs=nothing


Response.Redirect "creation.html"
%>
</body>
</html>


I haven't tested any of this ( I don't even have an IIS server to try on ), and I didn't confirm your FSO, create/write to file code. but this should get you moving in the right direction.

Old Pedant
02-19-2010, 08:29 PM
My bigger question: Why would you create a new text file for each new user???

Instead of using a database with one table and then one record for each user?

Old Pedant
02-19-2010, 08:33 PM
Ahhh...just noticed:

<input type="submit" name="usercreate" value="Create User"
onClick="parent.location='writetofile.asp'">

So is this happening in a <frame> or <iframe>????

Simply changing the parent.location WILL NOT AT ALL submit any of the form field values to that "writetofile.asp" page!!!!! The page will load, with NO FORM SUBMIT taking place.

*POSSIBLY* you could do it this way:

<form method="post" action="writetofile.asp" target="_top">
<input type="text" name="fname" size="25" maxlength="1" value="Enter your first initial"><br>
<input type="text" name="lname" size="25" maxlength="15" value="Enter your last name here"><br>
<input type="submit" name="usercreate" value="Create User">
</form>

That is Angst's code but with the target changed to, I think, refer to the main parent page.

nvysel24
02-20-2010, 12:53 AM
My bigger question: Why would you create a new text file for each new user???

Instead of using a database with one table and then one record for each user?

lol well good question this is still in progress of working at actually that was going to be my next question. ill give you some background info
my ftp server user .ini files for accounts stores all info in them

i know that may not be the most efficient way to do things but this is just a personal server to dink around on and only let friends connect to so mainly this is enjoyment even though i suck at coding

but to answer your question once it is done it will not create the text file that you saw text.txt like so


Set wfile = fs.CreateTextFile("C:\test.txt", True)


instead at the end product which im still working on it will create a new ini file with the username they chose


Set wfile = fs.CreateTextFile("C:\"&fname&lname&".ini", True)


i am just trying to figure out the basics right now

Old Pedant
02-20-2010, 02:54 AM
Okay, that's a reasonable way to do it then. Good luck.

nvysel24
02-20-2010, 05:28 AM
*POSSIBLY* you could do it this way:

<form method="post" action="writetofile.asp" target="_top">
<input type="text" name="fname" size="25" maxlength="1" value="Enter your first initial"><br>
<input type="text" name="lname" size="25" maxlength="15" value="Enter your last name here"><br>
<input type="submit" name="usercreate" value="Create User">
</form>

That is Angst's code but with the target changed to, I think, refer to the main parent page.
I just had 2 quick ?'s
1 was pertaining to the code target="top". if i understand it right your saying _top refers to the page that it was just on right?

also myabe i should be using a different function or something because having problems if i dont have a text file already created called text.txt in the root of c it errors out because its not there but if i have it created it wont error out and it will fill in the text [Account] like it is supposed to.
this is sort of contra productive because i need it to create one. not check to see if its there then write in it.

here is the code as i have it

<%
createaccount="[Account]"

Set fs = CreateObject("Scripting.FileSystemObject")

Set wfile = fs.CreateTextFile("C:\test.ini", True)
wfile.Write (createaccount)

wfile.close
Set wfile=nothing
Set fs=nothing

Response.Redirect "creation.html"
%>
</body>



also if i have this code at the top of the writetofile.asp page it errors our and says error 500 internal server error and doesnt tell me anything. This in theory is supposed to get the variables from the last page's form

fname = request.post("fname")
lname = request.post("lname")


Edit:
I figured out the last problem i was having
had to look up the syntax of calling somthing in a form and had to change it from
fname =request.post("fname")
to
fname = request.form("fname")
i would assume its passing the variables now now i jus need to create the syntax for it using those variables as the .ini file name

Old Pedant
02-20-2010, 08:13 PM
It's possible that most of your problems come from IIS not having permissions to create files in the root (C:\) directory.

By default, it certainly would not have such permissions.

I wouldn't really recommend granting those permissions, either, but if you have to in order to do this, then you have to.

You would need to grant permission to the "IUSR_xxxx" account, where "xxxx" is the name of the computer. Fair warning: If the IIS user ever "catches" a virus, your entire machine is now really vulnerable.

Is there any way you can make this work by creating the files in some specific directory, instead of in the root? Then you could just give permissions in that directory and it's much safer.

And I thought you were going to change to using something like this:
Set wfile = fs.CreateTextFile("C:\" & fname & lname & ".ini", True)

???

Old Pedant
02-20-2010, 08:14 PM
Oh...and, yes, I *THINK* that using
<form target="_top">
will send the results of the form posting to the main window. It works for <a href=xxx target="_top"> so I assume it would work for <form>. Untested.

nvysel24
02-20-2010, 10:02 PM
Is there any way you can make this work by creating the files in some specific directory, instead of in the root? Then you could just give permissions in that directory and it's much safer.

yes that is what i was going to do. i didnt think about the permissions issue but the root was just to test if i could create the file and fill in the needed information


And I thought you were going to change to using something like this:[code]
Set wfile = fs.CreateTextFile("C:\" & fname & lname & ".ini", True)


also wth this code it worked i actually found this last night at like 4 in the morning. that code is exactly what i had after i fixed the request.form

Set wfile = fs.CreateTextFile("C:\"&fname&lname&".ini", true)

i got it all working except for creating the file so i will try what you suggested in a few minutes

nvysel24
02-21-2010, 08:46 AM
Hey Thanks Old Pedant for your help i got it working it was just a permissions issue but instead of it being the IUSRmycomputername it was actually Users needing write access.

And since im guessing some other person will eventually stumble into the same problem ill post my code to help you guys out whoever that may be

this was in my createaccount.html

<form method="post" action='creation.asp' >

<input type="text" name="fname" size="25" maxlength="1" value="Enter your first initial"><br>
<input type="text" name="lname" size="25" maxlength="15" value="Enter your last name here"><br><br>
<input type="submit" name="usercreate" value="Create User"
</form>


and this was in my creation.asp

<%
response.write(request.form("fname"))
response.write(request.form("lname"))
fname = request.form("fname")
lname = request.form("lname")
dim fs,wfile
createaccount="[Account]"
Set fs = CreateObject("Scripting.FileSystemObject")
Set wfile = fs.CreateTextFile("C:\Program Files\g6\Accounts\Mydomain\users\"&fname&lname&".ini", true)

wfile.Write (createaccount)
wfile.close
Set wfile=nothing
Set fs=nothing


%>