post html to asp.net page for validation and emailing

C

csteacy

Hello,
I am pretty new to asp.net and I've been trying to figure out how to
take a static HTML web form data and send it to an asp.net page to
validate 1 field and then if it passes the validation, create an e-
mail message using jmail and send it to the specified e-mail address.
I've tried using an if then else statement but am really lost in the
coding. I've added some code below to give an idea of what I'm trying
for the asp.net page:

<%@Page Language="VB" validateRequest="false" %>
<%@Import Namespace="Dimac.JMail" %>
<html>
<title>validate</title>
<body bgcolor="#FFFFFF">
<%
Dim validate

Validate = Trim(Request.Form("validate"))
' Check the message field for input if is blank
' then add to the display message
If validate() = "" Then
Response.Redirect("notsent.html")

' If all seems ok begin processing the email
Else
Sub Page_Load( ByVal sender As Object, Byval e As EventArgs )
Dim obj As New Message()
Message.From.Email = "(e-mail address removed)"
Message.To.Add("(e-mail address removed)", "")
Message.Bcc.Add("(e-mail address removed)", "")
Message.Subject = "form subject"
Message.BodyText = "Phone: " & Request.Form("txtphone")


Try
Smtp.Send(Message, "smtpserver")
Response.Redirect("submitted.html")

Catch ex As Exception

End Try
End Sub
End If%>
</body>
</html>

I'm posting the HTML page to the asp.net page but with no results.
Could someone point me in the right direction? Thank you in advance
for your help.
 
M

Mark Rae [MVP]

I'm posting the HTML page to the asp.net page but with no results.
Could someone point me in the right direction? Thank you in advance
for your help.

There's no need to have a separate HTML page...

1) Place your form fields in an aspx page

2) Add an <asp:Button> webcontrol

3) Either use Validation controls or roll your own client-side JavaScript or
server-side VB.NET / C#...
 
C

csteacy

There's no need to have a separate HTML page...

1) Place your form fields in an aspx page

2) Add an <asp:Button> webcontrol

3) Either use Validation controls or roll your own client-side JavaScript or
server-side VB.NET / C#...

Thank you for your response to this. I wish I could not use an HTML
page for this but I have to because of the content management system
that we have. It does HTML forms but not any function with the forms
so I have to set the form to go to different page that can validate
and e-mail the form. I can't add in Javascript or anything to the
HTML page because it's inside the content management system. I've
tried to take the page and make it an asp.net page but then I cannot
get the same design. Is there another option? Thank you again.
 
M

Mark Rae [MVP]

Thank you for your response to this. I wish I could not use an HTML
page for this but I have to because of the content management system
that we have. It does HTML forms but not any function with the forms
so I have to set the form to go to different page that can validate
and e-mail the form. I can't add in Javascript or anything to the
HTML page because it's inside the content management system.

You didn't mention *any* of the above in your original post - we can only
work with the information you provide... :)
I've tried to take the page and make it an asp.net page but then I cannot
get the same design.

That doesn't make sense - an aspx page is nothing more than HTML (and
JavaScript) once it's rendered to the client browser...

What is providing the HTML page's design...?
 
J

Juan T. Llibre

re:
!> I wish I could not use an HTML page for this but I have to
!> because of the content management system that we have.
!> Is there another option?

Sure there is: change your content management system.

Clearly, it's hampering the development of your websites.
 
C

csteacy

re:
!> I wish I could not use an HTML page for this but I have to
!> because of the content management system that we have.
!> Is there another option?

Sure there is: change your content management system.

Clearly, it's hampering the development of your websites.

Thank you for your responses. The plan is in the works to move to a
new CMS soon because of limitations such as this. But for now
development must still proceed as business proceeds. Thank you again.
 
B

Brandon Gano

It looks like the problem is in your syntax (unless the code got jumbled
when you posted). Are you using Visual Studio to create the processing page?
If so, have you tried compiling the page to see if any errors come up?

The most obvious problem with the code you posted is that you have code
outside of a Sub and the Sub is illegally nested inside an If statement. Try
to move this line:

Sub Page_Load( ByVal sender As Object, Byval e As EventArgs )

Immediately after the <% and move this line:

End Sub

Immediately before the %> (after End If). If that doesn't fix your problem,
and the page compiles in VS, please reply with more specific information
about the problem.
 
C

csteacy

It looks like the problem is in your syntax (unless the code got jumbled
when you posted). Are you using Visual Studio to create the processing page?
If so, have you tried compiling the page to see if any errors come up?

The most obvious problem with the code you posted is that you have code
outside of a Sub and the Sub is illegally nested inside an If statement. Try
to move this line:

Sub Page_Load( ByVal sender As Object, Byval e As EventArgs )

Immediately after the <% and move this line:

End Sub

Immediately before the %> (after End If). If that doesn't fix your problem,
and the page compiles in VS, please reply with more specific information
about the problem.

Thank you very much for your suggestion, I made this switch and I have
two errors that come up in VS -

1) Statement cannot appear within a method body. End of method
assumed. (highlights Sub)

2) End Sub must be preceded by a matching Sub. (highlights End Sub).

I'm not sure what these mean but I'm looking into it.
Please let me know if you have more insight into this.
Thank you for all the help.
 
B

Brandon Gano

I would need to see more of the code in order to diagnose the problem. It
looks like you have a Sub within a Sub, which is not allowed.
 
C

csteacy

I figured this out, thanks to the help from here and some more cut/
paste/think/try etc. Here's the final code for those also in need of
it in the future.
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

Dim validate
validate = (Request.Form("validate").ToString())


If validate = "159" Then

' If all seems ok begin processing the email

Dim message As New Message()
message.From.Email = "(e-mail address removed)"
message.Subject = "Form Name"
message.BodyText = "Name: " & Request.Form("name")

Try
Smtp.Send(message, "smtpserver")
Response.Redirect("submitted.html")

Catch ex As Exception

End Try
Else
Response.Redirect("notsent.html")
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top