Forum Moderators: open

Message Too Old, No Replies

Code processes form, but deletes a field

How can i resolve this?

         

Googly

8:32 am on Jul 18, 2003 (gmt 0)


The ASP code below processes a form with 3 fields, 'name', 'email' and 'message'. If a field is empty and the user clicks submit, it will return the user to the form to fill in the empty fields. As you can see this behaviour is 'attached' to each field of the form. However, for the 'message' field I do not want the user to HAVE to fill it in. If I delete the behaviour from the 'message' field, the user can fill in 'name', leave 'email' blank, and fill in 'message', but when it returns the user to the form to fill in 'email' it deletes the content of the 'message' field. Is there a solution which will not delete the 'message' content, but will also allow the user to not fill that field in? Hope that's clear.

[code]
<%

name = request.form("name")
email = request.form("email")
message = request.form("message")

If name="" or email="" or message="" Then
url = "contact.asp?reqd=* indicates required field&name=" & name & "&email=" & email & "&message=" & message
If name="" Then
url = url & "&mname=*"
End if

If email="" Then
url = url & "&memail=*"
End if

If message="" Then
url = url & "&mmessage=*"
End if

response.redirect url & "&foobar=foobar#form"
response.end
End if

Dim objCDONTS ' Email object
Dim strFromName ' From persons' real name
Dim strFromEmail, strToEmail ' Email addresses
Dim strSubject, strBody ' Message
Dim misccompo


strSubject = "dcs"
strFromName = Trim(Request.Form("name"))
strFromEmail = Trim(Request.Form("email"))
strToEmail = "mark@dcs-imago.com"
strBody = Trim(Request.Form("message"))

Set objCDONTS = Server.CreateObject("CDONTS.NewMail")
objCDONTS.From = strFromName & " <" & strFromEmail & ">"
objCDONTS.To = strToEmail
objCDONTS.Subject = strSubject
objCDONTS.Body = "--------------------------------------" & vbcrlf & vbcrlf & strbody & vbcrlf & vbcrlf & vbcrlf & "--------------------------------------------------------------" & vbcrlf & "MESSAGE ENDS: End of message"
objCDONTS.Send
Set objCDONTS = Nothing

response.redirect "thanks.asp"
response.end
%>
[/code]

le_gber

10:21 am on Jul 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would do it like that:

<%
dim contactName, contactEmail, contactMessage, isSubmitted, nameRequired, EmailRequired

isSubmitted = request.form("the_name_of_your_submit_button")

If isSubmitted <> "the_label_of_your_submit_button" Then
contactName = ""
contactEmail = ""
contactMessage = ""
nameRequired =""
emailRequired =""
Else
contactName = request.form("name")
contactEmail = request.form("email")
contactMessage = request.form("message")
End If

If contactName="" or contactEmail="" then
nameRequired = "Please enter your name"
emailRequired = "Please enter your Email"
Else
Dim objCDONTS ' Email object
Dim strFromName ' From persons' real name
Dim strFromEmail, strToEmail ' Email addresses
Dim strSubject, strBody ' Message
Dim misccompo

Set objCDONTS = Server.CreateObject("CDONTS.NewMail")
objCDONTS.From = contactName & " <" & contactEmail & ">"
objCDONTS.To = "mark@dcs-imago.com"
objCDONTS.Subject = "dcs"
objCDONTS.Body = "--------------------------------------" & vbcrlf & vbcrlf & contactMessage & vbcrlf & vbcrlf & vbcrlf & "--------------------------------------------------------------" & vbcrlf & "MESSAGE ENDS: End of message"
objCDONTS.Send
Set objCDONTS = Nothing

response.redirect "thanks.asp"
response.end
end if
%>

and in your html body
<table width="420" border="0" cellspacing="0" cellpadding="0">
<form name="contact" method="post" action="contact.asp">
<tr>
<td width="150">Name</td>
<td width="150">
<input type="text" name="name" value="<%=contactName%>">
</td>
<td><%=nameRequiredMessage%></td>
</tr>
<tr>
<td width="150">Email</td>
<td width="150">
<input type="text" name="email" value="<%=contactEmail%>">
</td>
<td><%=EmailRequiredMessage%></td>
</tr>
<tr>
<td width="150">Comment</td>
<td width="150">
<textarea name="comment"><%=contactMessage%></textarea>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="150">&nbsp;</td>
<td width="150">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="reset" value="Reset">
</td>
<td>&nbsp;</td>
</tr>
</form>
</table>

Hope I didnt' make mistakes ;) Let me know if it works

Leo

Googly

12:11 pm on Jul 18, 2003 (gmt 0)



mmm leo..unless i'm not doing something correct, i can't get it to work..any ideas?

le_gber

1:27 pm on Jul 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



sorry about that

Just copy and paste it ;)

Leo

<%
dim contactName, contactEmail, contactMessage, isSubmitted, nameRequired, EmailRequired

isSubmitted = request.form("submit")

If isSubmitted <> "isSubmit" Then
contactName = ""
contactEmail = ""
contactMessage = ""
nameRequiredMessage =""
EmailRequiredMessage =""
Else
contactName = request.form("name")
contactEmail = request.form("email")
contactMessage = request.form("message")
End If

if contactName="" then
nameRequiredMessage = "Please enter your Name"
end if

if contactEmail="" then
EmailRequiredMessage = "Please enter your Email"
end if

If contactName<>"" and contactEmail<>"" then
Dim objCDONTS ' Email object
Dim strSubject, strBody ' Message
Dim misccompo

Set objCDONTS = Server.CreateObject("CDONTS.NewMail")
objCDONTS.From = contactName & " <" & contactEmail & ">"
objCDONTS.To = "mark@dcs-imago.com"
objCDONTS.Subject = "dcs"
objCDONTS.Body = "--------------------------------------" & vbcrlf & vbcrlf & contactMessage & vbcrlf & vbcrlf & vbcrlf & "--------------------------------------------------------------" & vbcrlf & "MESSAGE ENDS: End of message"
objCDONTS.Send
Set objCDONTS = Nothing

response.redirect "thanks.asp"
response.end
end if
%>


%>

<html>
<body>
<table width="499" border="0" cellspacing="0" cellpadding="0">
<form name="contact" method="post" action="contact.asp">
<tr>
<td width="150">Name</td>
<td width="150">
<input type="text" name="name" value="<%=contactName%>">
</td>
<td width="199"><font face="Arial, Helvetica, sans-serif" size="1"><%=nameRequiredMessage%></font></td>
</tr>
<tr>
<td width="150">Email</td>
<td width="150">
<input type="text" name="email" value="<%=contactEmail%>">
</td>
<td width="199"><font face="Arial, Helvetica, sans-serif" size="1"><%=EmailRequiredMessage%></font></td>
</tr>
<tr>
<td width="150">Comment</td>
<td width="150">
<textarea name="message"><%=contactMessage%></textarea>
</td>
<td width="199">&nbsp;</td>
</tr>
<tr>
<td width="150">&nbsp;</td>
<td width="150">
<input type="submit" name="Submit" value="isSubmit">
<input type="reset" name="reset" value="Reset">
</td>
<td width="199">&nbsp;</td>
</tr>
</form>
</table>
</body>
</html>

Googly

3:59 pm on Jul 18, 2003 (gmt 0)



looking good, i'll do some more on Monday
cheers mate

le_gber

5:38 pm on Jul 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



no pb let me know, I'd like to get more into ASP also, so if you hit a wall, I'll try to help you as much as I can :)

Leo

Googly

1:04 pm on Jul 28, 2003 (gmt 0)



ok le_gber I have got it all working nice and smoothly and have added some more form fields, so thanks a lot for that. Next thing I am looking to do is for the .asp page to email a short message to the email address which has been typed in by the user. i.e. an autoresponder 'thanks for...'. What code can I add to the code above to create an autoresponder in addition to the .asp sending the form details to me?

le_gber

7:33 am on Jul 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



what about having the redirect page dealing with that?

Leo

Googly

9:00 am on Jul 29, 2003 (gmt 0)



I understand where you're coming from, but how would I get the email address from the form to also be sent to the redirect page?

le_gber

2:54 pm on Jul 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you could add it dynamically to the querystring of the redirect page with the name and you could write your email as

Dear <%request.querystring("name")%>,

and your email body here

Leo

Googly

9:34 am on Jul 30, 2003 (gmt 0)



okay I'm still grasping the basics whilst using trial and error, but how in the example above would I also send the email address via a QueryString to the confirmation (redirect) page?

Googly

le_gber

4:57 pm on Jul 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



response.redirect "thanks.asp?email=" & contactEmail

I think :)

and on the thanks.asp, you've got the script to send the email above the <html> (with request.querystring("email")and your visible message in the html body.

Leo

Googly

1:37 pm on Aug 1, 2003 (gmt 0)



leo your help has been outstanding and much appreciated. The code is now working and working smoothly. As an ASP beginner, thanks to you I have learnt a lot from this first step.

Cheers
Googly

le_gber

2:35 pm on Aug 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No pbs glad I could be of help

C U around :)

LEo