Click to See Complete Forum and Search --> : Server-side forms
timboyk12
06-13-2005, 03:10 PM
I posted earlier for using some type of language for form validation. However, I really have no idea what I'm doing. Is there a program for PHP or any language I could use or would anyone be willing to help? Thanks a lot!!!
Tim
buntine
06-13-2005, 07:14 PM
Yer. Show us your form and we can help you with validation.
Note, this is the ASP forum.
timboyk12
06-14-2005, 07:59 AM
Thanks I would really appreciate it. Here is my code:
<FORM ACTION="" METHOD="POST"><TABLE>
<TR><TD>Course:</TD><TD><INPUT TYPE="TEXT" SIZE="35" NAME=COURSE></TD></tr>
<TR><TD>Student Name:</td><td><INPUT TYPE="TEXT" SIZE="35" NAME=STUDENT></td></tr>
<tr><td>Grade:</td><td><SELECT NAME=GRADE><OPTION NAME=GRADE9>9</option><OPTION NAME=GRADE10>10</option>
<OPTION NAME=GRADE11>11</option><OPTION NAME=GRADE12>12</option></select></td></tr>
<tr><td>Home phone number:</td><td><INPUT TYPE="TEXT" SIZE="35" NAME=HOMEPHONE></td></tr>
<tr><td>Student Number:</td><td><INPUT TYPE="TEXT" SIZE="7" NAME=STUDENT ID></td></tr>
<tr><td>Home Address:</td><td><INPUT TYPE="TEXT" SIZE="35" NAME=HOMEADDRESS></td></tr>
<TR><TD>Guidance Counselor</td><td><INPUT TYPE="TEXT" SIZE="35" NAME=COUNSELOR></td></tr>
<tr><td>Home Room Teacher</td><td><INPUT TYPE="TEXT" SIZE="35" NAME=HOMEROOM></td></tr>
<TR><TD COLSPAN=2 align=center><INPUT TYPE=SUBMIT VALUE="SUBMIT"></tD></tr>
</form>
Thanks again!
-Tim
timboyk12
06-14-2005, 01:37 PM
i'm sorry if i was confusing in my question, but i want the form to be saved to a database, which now i realize is probably not the same thing as validation
sorry for any confusion
Tim
buntine
06-14-2005, 01:40 PM
Ok, before I go into detail, does your server support ASP? If you are running a Windows server, then you should be fine.
Regards.
timboyk12
06-14-2005, 01:46 PM
yes, i'm running windows server and it supports pretty much anything so whichever language is easiest for you to explain...
Thanks again
Tim
buntine
06-14-2005, 03:52 PM
Ok. Your going to have to grab all the input data and then generate an SQL query, which inserts the data into the database.
First, you will need to declare, and define, your objects and variables.
Dim objConn
Dim strConnString, strSqlQuery
Dim strCourse, strStudent, strGrade, strHomePhone,
Dim strStudentID, strHomeAddress, strCounselor, strHomeRoom
Set objConn = Server.CreateObject("ADODB.Connection")
strConnString = "YourConnectionString" '| Consult your server admin if unsure.
objConn.Open strConnString
strCourse = Request.Form("course")
strStudent = Request.Form("student")
strGrade = Request.Form("grade")
strHomePhone = Request.Form("homePhone")
strStudentID = Request.Form("student_id")
strHomeAddress = Request.Form("homeAddress")
strCounselor = Request.Form("counselor")
strHomeRoom = Request.Form("homeRoom")
From here you can validate the data. Alot of work can be placed into validation to ensure the user does exactly what they are supposed to do. But, to keep on track, I will just highlight some extremely basic validation. We will just make sure the user has entered a value for "Course" and "Student".
If strStudent = "" Then
Response.Write("- Form field ""Student"" must contain a value.")
Response.End
ElseIf strCourse = "" Then
Response.Write("- Form field ""Course"" must contain a value.")
Response.End
End If
Now we generate the SQL query. I do not know how your database is designed, so I will just assume there is one table with the same fields as presented in the form.
strSqlQuery = "INSERT INTO yourTableName (course, student, grade, homephone, student_id, homeaddress, counselor, homeroom)" & _
"VALUES ('" & strCourse & "', '" & strStudent & "', '" & strGrade & "', '" & strHomePhone & "', '" & strStudentID & "', '" & strHomeAddress & "', '" & strCounselor & "', '" & strHomeRoom & "');"
Finally, we can execute the query and clean up.
objConn.Execute strSqlQuery
objConn.Close
Set objConn = Nothing
This should get you started.
Regards.
buntine
06-14-2005, 03:56 PM
I have modified your form a bit to comply with my example:
<FORM ACTION="CreateRecord.asp" METHOD="POST"><TABLE>
<TR><TD>Course:</TD><TD><INPUT TYPE="TEXT" SIZE="35" NAME="COURSE"></TD></tr>
<TR><TD>Student Name:</td><td><INPUT TYPE="TEXT" SIZE="35" NAME="STUDENT"></td></tr>
<tr><td>Grade:</td><td><SELECT NAME="GRADE"><OPTION value="GRADE9">9</option><OPTION value="GRADE10">10</option>
<OPTION value="GRADE11">11</option><OPTION value="GRADE12">12</option></select></td></tr>
<tr><td>Home phone number:</td><td><INPUT TYPE="TEXT" SIZE="35" NAME="HOMEPHONE"></td></tr>
<tr><td>Student Number:</td><td><INPUT TYPE="TEXT" SIZE="7" NAME="STUDENT_ID"></td></tr>
<tr><td>Home Address:</td><td><INPUT TYPE="TEXT" SIZE="35" NAME="HOMEADDRESS"></td></tr>
<TR><TD>Guidance Counselor</td><td><INPUT TYPE="TEXT" SIZE="35" NAME="COUNSELOR"></td></tr>
<tr><td>Home Room Teacher</td><td><INPUT TYPE="TEXT" SIZE="35" NAME="HOMEROOM"></td></tr>
<TR><TD COLSPAN="2" align="center"><INPUT TYPE="SUBMIT" VALUE="SUBMIT"></tD></tr>
</form>
Make a file called InsertRecord.asp and work fomr there. Place it in the same directory as your HTML file.
By convention, it is best write all markup in lower-case and encase all parameter values in double quotes.
Regards.
timboyk12
06-14-2005, 04:18 PM
This might sound really stupid but what is a MySQL database? Is it possible to use something like an access file instead or no?
buntine
06-14-2005, 04:24 PM
MySQL is a free database available from www.mysql.com (see site for info).
MS Access can be used with ASP. All you have to do is supply an appropriate connection string. Contact your host or server admin.
May I ask; why are you actually creating this application?
Regards.
timboyk12
06-14-2005, 04:31 PM
I actually teach web design at a high school and need to collect student information 4 times a year. If I give my students paper forms, I have to type 1000+ names into a database which is extremely time consuming. By putting this form on the server I will hopefully save some time and get the course going faster. (the course is in html, javascript, and css, some DHTML, but no server-side scripts)
timboyk12
06-14-2005, 04:37 PM
What exactly does the connection string do? The admins at the school are not very, umm "intelligent" and they might not know what i'm talking about.
THanks
buntine
06-14-2005, 05:31 PM
The connection string is a string of text that informs the server which data driver to use and which Data Source Name (DSN) to use. You can use a DSN-less connection by providing the file location and name of your access database (along with a username and password, if necessary).
I have also sent you a private message. :)
Regards.
check out connectionstrings.com for a list.
timboyk12
06-15-2005, 06:07 PM
can someone look at my site http://whrhs2007.somee.com/forms.htm and see what is wrong and why it is showing me the asp document instead of actually interpretting it.
THANKS
Tim
buntine
06-15-2005, 11:03 PM
Your server does not support ASP or ASP has been disabled. The source code is not being passed through the ASP engine so it is just being treated as flat text.
You will need to speak to the server admins and ask them about it.
Regards.