...

View Full Version : Need help with form in asp



rjkdonaldson
09-04-2007, 03:12 PM
Hi was wandering if anyone could help me with my form, I need it to be processed and have user names written to a text file the code is in html format and I kinda need asp code to process it ie write to textfile.Please help as I am still experimenting. here is da form and script within the appropriate head tags.


<head>
<script language=javascript>
function checkWholeForm(frm) {
var why="";
why += first_name(frm.fn.value);
why += last_name(frm.ln.value);
why += checkAdd(frm.add.value);
why += check_ph(frm.ph.value);
why += checkEmail(frm.em.value);

function first_name (strng){
var error="";
if (strng=="") {
error = "First name field empty.\n";
alert(error)
}
}
function last_name (strng){
var error="";
if (strng=="") {
error = "Last name field empty.\n";
alert(error)
}
}
function checkAdd (strng){
var error="";
if (strng =="") {
error = "Address field empty.\n";
alert(error)
}
}
function check_ph (strng) {
var error = "";
if (strng == "") {
error = "Phone number field empty.\n";
alert(error)
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
if (isNaN(parseInt(stripped))) {
error = "The phone number contains illegal characters.";

}
if (!(stripped.length == 10)) {
error = "The phone number is the wrong length. Make sure you included an area code.\n";
}
alert(error)
return error;
}


function checkEmail (strng) {
var error = "";
if (strng == "") {
error = "Email field is empty.\n";
alert(error)
}

var emailFilter=/^.+@.+\..{2,3}$/; // includes blank field
if (!(emailFilter.test(strng))&&(strng !="")) {
error = "Please enter a valid email address.\n";

}

else {
//test email for illegal chars
var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
if (strng.match(illegalChars)) {
error="The email address contains illegal characters.\n";

}
}
alert(error)
return error;
}
}
</script>
</head>
<form name=frm action="" onsubmit="return checkWholeForm(frm)">
First name:&nbsp;<input type=text name=fn><br>
Last name:&nbsp;<input type=text name=ln><br>
Address:&nbsp;<input type=text name=add><br>
Phone:&nbsp;<input type=text name=ph><br>
Email address:&nbsp;<input type=text name=em><br><br>&nbsp;&nbsp;&nbsp;<input type=submit name=sb value=Submit>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type=reset name=rb value=Clear>
</form>

Daemonspyre
09-04-2007, 03:53 PM
Using JS to do your error checking is not the best practice, but should be only one of multiple versions of error checking.

Remember, there are people out there who do browse sites w/ JS turn OFF.

But, to answer your question, you would use the Scripting.FileSystemObject.

This would be done after the HEAD tags, but before the BODY tags.

Here's the MSDN link to the FileSystemObject. http://msdn2.microsoft.com/en-us/library/d6dw7aeh.aspx

ido3dfx
09-04-2007, 06:44 PM
Your submit button has no action. It has a validator tied into the java but you are not sending this any where after that.

So right now it will do what ever you want the validatior to do but then what?

process the form?
send the form fields to a ASP page for processing and display a think you?

:confused:

rjkdonaldson
09-05-2007, 02:39 AM
quite new to asp I just want the form values displayed as output on html page get it still delving into it though.

Daemonspyre
09-05-2007, 05:43 AM
If you just want to display the objects, then you can use the REQUEST method.

Try this simple form first (notice the uppercase change to your form):


<%
' To display form values you can use the REQUEST OBJECT, one item at a time
'
if request.form("First") <> "" then
response.write("First Name: " & request.form("First") & "<br />" & vbCrLf)
'...
'...
end if
'
' OR you can use a FOR NEXT Loop to display the values
'
for each fld in request.form
response.write(fld & ": " & request.form(fld) & "<br />")
next
%>

<form METHOD=POST name=frm action="">
First name:&nbsp;<input type=text name=fn><br>
Last name:&nbsp;<input type=text name=ln><br>
Address:&nbsp;<input type=text name=add><br>
Phone:&nbsp;<input type=text name=ph><br>
Email address:&nbsp;<input type=text name=em><br><br>&nbsp;&nbsp;&nbsp;<input type=submit name=sb value=Submit>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type=reset name=rb value=Clear>
</form>

rjkdonaldson
09-05-2007, 05:51 AM
If you just want to display the objects, then you can use the REQUEST method.

Try this simple form first (notice the uppercase change to your form):


<%
' To display form values you can use the REQUEST OBJECT, one item at a time
'
if request.form("First") <> "" then
response.write("First Name: " & request.form("First") & "<br />" & vbCrLf)
'...
'...
end if
'
' OR you can use a FOR NEXT Loop to display the values
'
for each fld in request.form
response.write(fld & ": " & request.form(fld) & "<br />")
next
%>

<form METHOD=POST name=frm action="">
First name:&nbsp;<input type=text name=fn><br>
Last name:&nbsp;<input type=text name=ln><br>
Address:&nbsp;<input type=text name=add><br>
Phone:&nbsp;<input type=text name=ph><br>
Email address:&nbsp;<input type=text name=em><br><br>&nbsp;&nbsp;&nbsp;<input type=submit name=sb value=Submit>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type=reset name=rb value=Clear>
</form>

will give it a go

rjkdonaldson
09-05-2007, 08:51 AM
Created a dummy html form and used response.write(First name: " & fn(button name) & " to return text input and it work found w3schools website to be of some use. thanks for the help though



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum