PDA

View Full Version : How to write a good form in ASP



Mr Chunder
May 16th, 2001, 02:26 PM
I was wondering about the best method to write a form in ASP and make it a bit of a corporate standard.

There are all sorts of methods of writing an ASP form but basically you want to do the following:

1. Startup and read values from a database
2. Display values on the form
3. User can edit them and hit either cancel or submit
4. On submit, validate the data on the form
5. If invalid, return the user to the form pointing out the errors
6. Goto 3.


A solution that I reckon is the best is to:

1. Use only one ASP page for the whole process

2. The single page is structured as follows:

if this has just been submitted (we are using one page for everything)
Validate data on form
Check for dodgy characters that break SQL or display such as ', > < etc.
if dodgy data then
Return page to user with all previous user input

else
save data to database

else
retrieve data from database (if exists)
display to user
end if

Use post method to the same ASP page


I reckon this is the best standard approach since this has the following advantage:
1. All activity is in one place
2. All validation routines such as email addresses or check for dodgy characters would be standard and located in asp includes for reuse

What are opinions of seasoned ASP programmers ? Anyone with a better approach ?

antoniyo
Nov 10th, 2008, 04:53 AM
You need one HTML form to collect the data and send them to an ASP page, and the ASP page takes the data from the form and send them to an email.

**NOTE: I have trimmed the code from the source so that it becomes readable.


HTML form:

<form method="POST" action="form_ac.asp" name="form1"><br>
name:<input type="text" name="name"><br>
email:<input type="text" name="email"><br>
message:<br><textarea name="message" cols="40" rows="5"></textarea><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Reset" value="Reset">




ASP page:

<%@ Language="VBscript" %>
<% Option Explicit %>



<%

Dim name, email, message, NewMailObj
name=request.form("name")
email=request.form("email")
message=request.form("message")


Set NewMailObj=Server.CreateObject("CDONTS.N...
NewMailObj.From = "michael@codefixer.com"
NewMailObj.To = "whoever_you_want_to_send_it_to@hotmail....
NewMailObj.Subject = "New message sent.."
NewMailObj.Body = "the name you entered was " & name & _
"<br>the email was " & email & _
"<br>the message was " & message

'you need to add the following lines FOR the mail to be sent in HTML format
NewMailObj.BodyFormat = 0
NewMailObj.MailFormat = 0
NewMailObj.Send

Set NewMailObj = nothing
Response.write "The email was sent."
%>