This is my contact form that I want to connect to email upon form submission. I have researched on the net to do it but I cannot seem to run the codes.
I have two files where one is the html codes and another consists of the asp codes.
Need help on this please. Will appreciate your guidance.
<body>
<h3>Contact Form</h3>
<form name="form1" method="post" action="process.asp">
<label for="name">name</label>
<input type="text" id="name" name="name" placeholder="Your web id.."/>
<br><br>
<label for="deptID">Department ID</label>
<input type="text" id="deptID" name="departmentID" placeholder="Your department ID..">
<br><br>
<label for="issue">Issue</label>
<select id="issue" name="issue">
<option value="">Non-Availability of Test Points</option>
<option value="">Unable to Change Cycle Time Value</option>
<option value="">Unable to Retrieve Report</option>
</select>
<br><br>
<label for="subject">Additional Message</label>
<textarea id="subject" name="subject" placeholder="Write something.." style="height:200px"></textarea>
<br><br>
<input type="submit" value="Submit">
</form>
This is the process.asp page.
<%
formname = Request.Form("name")
formID = Request.Form("departmentID")
formquery = Request.Form("issue")
formsubject = Request.Form("subject")
Set Mail = Server.CreateObject("CDONTS.NewMail")
Mail.From = formname
Mail.FromName = formname
Mail.AddAddress "test#gmail.com"
Mail.Subject = "Form submitted from web site"
Bodytxt = "Details of Form submission :" & VbCrLf & VbCrLf
Bodytxt = Bodytxt & "Contact Name : " & formname & VbCrLf
Bodytxt = Bodytxt & "ID : " & formID & VbCrLf
Bodytxt = Bodytxt & "Query Entered : " & formquery & VbCrLf
Bodytxt = Bodytxt & "Subject Entered : " & formsubject
Mail.Body = Bodytxt
Mail.Username = "me#gmail.com"
Mail.Password = "password"
Mail.Host = "smtp.gmail.com"
Mail.Port = "587"
Mail.Send
Set Mail = Nothing
%>
Not sure whats going on with your code snippets but they look extremely incomplete, you need a heap more than that to join an ASP page to a backend set of code.
A standard setup using C# and ASP.Net is the following. Say my page is called "Default.aspx"
This would be my (As you called is HTML, but really you mean your ASP)
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
And then joined to this would be the C# ASP.Net
That would look something like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
What you have done above will never work, there is nothing referencing between the two files, your first piece of code is just plain html not ASP and there is nothing that defines your C# environment.
What I would suggest, get Visual Studio 2015 (Its free) and then click "New" and select ASP Website. Once you have done that click your new project and hit "Add Web Form" that will give you a good start, then you can start adding your form and code.
Caz
Related
I'm trying to create a sub function in classic asp that shows Password: the text space ? Any suggestions?
Sub GetPassword()
response.write " Password:"
<input type="text" name="txtEmPwd" size="20" value="<%=strEmPwd%>"> 1st 3 chars of
last name <input type="text" name="txtFirst3" size="5" maxlength=3 value="<%=strFirst3%>">
end sub
I get an error where the greater than character
Microsoft VBScript compilation error '800a0400'
Expected statement
That's because you are writing html directly in server side code.
You have to add the html as a string, something like this:
Sub GetPassword()
dim html
html = "Password:"
html = html & "<input type='text' name='txtEmPwd' size='20' value='" & strEmPwd & "'> 1st 3 chars of last name "
html = html & "<input type='text' name='txtFirst3' size='5' maxlength='3' value='" & strFirst3 & "'>"
Response.Write html
end sub
I'm trying to make a login page powered by asp and sql. After clicking submit, the form will not even trigger (i.e. the error message will not even display if the fields are blank)
Here is my code:
<!DOCTYPE html>
<html>
<title>
Query
</title>
<link href="http://hr-computing/public/AlexS/Tests/Site.css" rel="stylesheet">
<body>
<div id="main">
<%
username = ""
password = ""
ErrorMessage = ""
if request.form <> "" then
username = Request.Form("firstname")
password = Request.Form("password")
if username = "" or password = "" then
ErrorMessage = "You must specify a username and password."
else
set conn=Server.CreateObject("ADODB.Connection")
conn.Open ="{private}
set rs=Server.CreateObject("ADODB.recordset")
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "Select firstname, PASSWORD FROM teachers WHERE firstname = '" & firstname & "'", conn
if rs.EOF = false then
if rs.fields("Password") = password then
Response.Redirect("http://hr-computing/public/AlexS/Tests/default.asp")
end if
end if
ErrorMessage = "Login failed"
end if
end if
%>
<h1>Login</h1>
<form method="post" action="http://hr-computing/public/AlexS/Tests/login.asp">
<fieldset>
<legend>Log In to Your Account</legend>
<ol>
<li>
<label>Username:</label>
<input type="text" id="firstname" name="firstname" />
</li>
<li>
<label>Password:</label>
<input type="password" id="password" name="password" />
</li>
<li>
<p><input type="submit" value="Login" /></p>
</li>
</ol>
</fieldset>
</form>
</div>
</body>
</html>
Someone tell me what is wrong, please.
Where do you print out your error message? It doesn't look like you have that displayed anywhere. Classic ASP is kind of painful about this stuff - but somewhere you need a
<%= ErrorMessage %>
call to display the login error.
As you are using asp.net so for validating username and password for empty you can use required field validator. Be sure to set validation group to both the textbox as well as submit button.
Situation:
I am imaging new systems using MDT Lite-Touch. I am trying to
customize the wizard to automate the naming of new systems so that
they include a prefix "AG-", a department code which is selected from
a drop-down box in the wizard page (eg. "COMM"), and finally the
serial number of the computer being imaged, so that my result in this
case would be "AG-COMM-1234567"
Progress:
I first created the HTML page which I will include below and added a script to the page to concatenate the pieces into a variable called
OSDComputername which, for testing, I could output in a msgbox and get
to display correctly.
The problem with this is I don't know how to trigger the script then assign it to the OSDComputername variable that is used throughout
the rest of the Light-Touch process.
I changed the script to a function and added it to DeployWiz_Initization.vbs then used the Initialization field in WDS to
call it. I'll include the function below.
The problem with this is I would get "Undefined Variable" for OSDComputername and I am not sure it is pulling the data from the HTML
correctly.
I tried adding the scripting into the customsettings.ini file after the "OSDComputername="
This resulted in the wizard just outputting my code in text as the computer name.
I am now trying adding variables to "Properties=" (eg.DepartmentName) in the customsettings.ini, pulling thier value
from the HTML Form and setting that value to the variable in my
function in DeployWiz_Initization.vbs and calling them after
"OSDComputername=" in the fashion "OSDComputername="AG-" &
%DepartmentName%" in customsettings.ini
I am rebuilding right now and will see how this goes
Any help would be appreciated.
The HTML page:
<HTML>
<H1>Configure the computer name.</H1>
<span style="width: 95%;">
<p>Please answer the following questions. Your answers will be used to formulate the computer's name and description.</p>
<FORM NAME="TestForm">
<p>Departmental Prefix: <!-- <label class=ErrMsg id=DepartmentalPrefix_Err>* Required (MISSING)</label> -->
<SELECT NAME="DepartmentalPrefix_Edit" class=WideEdit>
<option value="AADC">AADC</option>
<option value="AEM">AEM</option>
<option value="AIP">AIP</option>
<option value="COM">COM</option>
<option value="DO">DO</option>
<option value="DSOC">DSOC</option>
<option value="EDU">EDU</option>
<option value="EPE">EPE</option>
<option value="ITN">ITN</option>
<option value="LA">LA</option>
<option value="OAP">OAP</option>
<option value="SML">SML</option>
</SELECT>
</p>
<p><span class="Larger">Client's Net<u class=larger>I</u>D:</span>
<INPUT NAME="ClientNetID" TYPE="TEXT" ID="ClientNetID" SIZE="15"></p>
<p>Building: <!-- <label class=ErrMsg id=Building_Err>* Required (MISSING)</label> -->
<SELECT NAME="Building_Edit" class=WideEdit>
<option value="Academic Surge Facility A">Academic Surge Facility A</option>
<option value="Academic Surge Facility B">Academic Surge Facility B</option>
<option value="Caldwell">Caldwell</option>
<option value="Kennedy">Kennedy</option>
<option value="Roberts">Roberts</option>
<option value="Warren">Warren</option>
</SELECT>
</p>
<p>
<span class="Larger">Room <u class=larger>N</u>umber:</span>
<input type=text id="RoomNumber" name=RoomNumber size=15 />
</p>
</FORM>
</span>
</HTML>
The Function:
Function SetComputerName
OSDComputerName = "AG-" & oEnvironment.Item("DepartmentalPrefix_Edit")
ComputerDescription = oEnvironment.Item("DepartmentalPrefix_Edit") & ", " & oEnvironment.Item("ClientNetID") & ", " & oEnvironment.Item("RoomNumber") & " " & oEnvironment.Item("Building_Edit")
End Function
Issue Resolved!
The HTML page:
<H1>Configure the computer name.</H1>
<p>Please answer the following questions. Your answers will be used to formulate the computer's name and description.</p>
<FORM NAME="SetComputerNameForm">
<p>
<LABEL class="Larger"><u class="Larger">D</u>epartmental Prefix:</LABEL><br />
<SELECT NAME="DepartmentalPrefix_Edit" ID="DepartmentalPrefix_Edit" language=vbscript onpropertychange=ValidateSetComputerName AccessKey=D>
<option value="FOO">FOO</option>
<option value="DOE">DOE</option>
<option value="AFK">AFK</option>
<option value="BBL">BBL</option>
<option value="RTFM">RTFM</option>
</SELECT>
</p>
<p>
<LABEL class="Larger"><u class="Larger">C</u>lient's ID:</LABEL>
<br />
<INPUT NAME="ClientID" ID="ClientID" TYPE="text" ID="ClientID" SIZE="15" language=vbscript onpropertychange=ValidateSetComputerName AccessKey=C />
<label class=ErrMsg for=ClientID>* Required (MISSING)</label>
</p>
<p>
<LABEL class="Larger"><u class="Larger">B</u>uilding:</LABEL><br />
<SELECT NAME="Building_Edit" ID="Building_Edit" language=vbscript onpropertychange=ValidateSetComputerName AccessKey=B>
<option value="ASA">ASA</option>
<option value="ASB">ASB</option>
<option value="ASC">ASC</option>
</SELECT>
</p>
<p>
<LABEL class="Larger"><u class="Larger">R</u>oom Number:</span></LABEL>
<br />
<INPUT NAME="RoomNumber" ID="RoomNumber" TYPE="text" ID="RoomNumber" size="15" language=vbscript onpropertychange=ValidateSetComputerName AccessKey=R>
<label class=ErrMsg for=RoomNumber>* Required (MISSING)</label>
</p>
</FORM>
The Function:
Function ValidateSetComputerName
ParseAllWarningLabels
If Len(Document.SetComputerNameForm.ClientNetID.Value) < 1 OR Len(Document.SetComputerNameForm.RoomNumber.Value) < 1 THEN
ButtonNext.disabled = true
Else
Dim Department
Dim SerialNumber
Dim CID
Dim RoomNumber
Dim BuildingName
Dim Make
Dim Model
Department = Document.SetComputerNameForm.DepartmentalPrefix_Edit.Value
SerialNumber = oEnvironment.Item("SerialNumber")
CID = Document.SetComputerNameForm.ClientID.Value
RoomNumber = Document.SetComputerNameForm.RoomNumber.Value
BuildingName = Document.SetComputerNameForm.Building_Edit.Value
Make = oEnvironment.Item("Make")
Model = oEnvironment.Item("Model")
oEnvironment.Item("OSDComputerName") = "AG-" & Department & "-" & Right(SerialNumber,7)
oEnvironment.Item("ComputerDescription") = Department & ", " & CID & ", " & RoomNumber & " " & BuildingName & ", " & Make & " " & Model
ButtonNext.disabled = false
End If
End Function
The real change is in the Function how I needed to retrieve the values from my custom HTML screens. You will see in the working Function that I had to set each value using the format: Document.FormName.FieldName.Value
I could then use the built-in Environmental Items to collect the Make, Model, and Serial Number. Once I had all of the pieces, all of the user selections and built-in values, it was simply a matter of concatenating the strings in the order I wanted and assigning the value to the Environmental Items "OSDComputerName" and "ComputerDescription".
I also made use of ButtonNext.disabled to make all of the fields required before the user was able to continue to the next screen.
i have simple html page with 3 textboxes.
<form id="form1" method=get action="http://mysite.com/default.aspx" runat="server">
<div>
<input id="name" type="text" value="Amy" />
<input id="email" type="text" value="amy#jf.com"/>
<input id="phone" type="text" value="2125552512" />
</div>
<input id="Submit1" type="submit" value="submit" />
</form>
Now when it loads default.aspx i have this code in the vb backend on page_load.
Dim tbName As TextBox = Page.FindControl("Name")
Dim tbPhone As TextBox = Page.FindControl("Phone")
Dim tbEmail As TextBox = Page.FindControl("Email")
If page.request("name") & "" <> "" AndAlso tbname IsNot Nothing Then
tbname.text = page.request("name")
End If
If page.request("email") & "" <> "" AndAlso tbEmail IsNot Nothing Then
tbEmail.text = page.request("email") & ""
end If
If page.request("phone") & "" <> "" AndAlso tbphone IsNot Nothing Then
tbPhone.text = page.request("phone") & ""
End If
The page loads but is these textboxes are empty. what am i doing wrong?
If you want to be able to access those controls serverside, you'll need to add the runat="server" attribute to each of them.
Also, the TextBox type you're referencing is the ASP.NET control, which you aren't using. What you'd be using, once you add the runat="server" tags is HtmlInputText.
You can use the TextBox type by using the TextBox ASP.NET control instead of the <input> elements:
<asp:TextBox ID="name" runat="server" Value="Amy" />
If all your ASP.NET page is doing is processing the request from the form, then there's no need to reference any textbox or input controls - it won't be possible since they don't exist as ASP.NET controls. All you need to do is read the values from Request.QueryString.
If the intent is for the inputs to be visible and/or editable once they're on the ASP.NET page, I'd recommend moving the HTML form into your ASP.NET page.
it is not like this that webform functionate.
First, your input in your form needs to be server control: ex <asp:TextBox runat="server" id="name" Text="value" />
Then in your codebehind file you do not have to go through Page.FindControl("YourInput") but only this.YourInput.Text
This is my index.aspx form.
<form role="form" method="post" action="SendMail.aspx">
<div class="form-group">
<input type="text" class="form-control" id="name" name="name" placeholder="Name"
required>
</div>
<div class="form-group">
<input type="text" class="form-control" id="mobile" name="mobile" placeholder="Mobile Number"
required>
</div>
<div class="form-group">
<input type="email" class="form-control" id="email" name="email" placeholder="Email"
required>
</div>
<button type="submit" id="submit" name="submit" class="btn btn-primary pull-right">
Submit Form</button>
</form>
And this is my SendMail.aspx form.
<%
Response.Write("Need : " & Request.Form("whatneed") & "<br>")
Response.Write("Budget : " & Request.Form("budget") & "<br>")
Response.Write("When : " & Request.Form("whenneed") & "<br>")
Response.Write("Location : " & Request.Form("location") & "<br>")
Response.Write("Name : " & Request.Form("name") & "<br>")
Response.Write("Description : " & Request.Form("address") & "<br>")
Response.Write("Mobile No : " & Request.Form("mobile") & "<br>")
Response.Write("Landline No : " & Request.Form("landline") & "<br>")
Response.Write("Email Id : " & Request.Form("email") & "<br>")
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add("saravana17.ams#gmail.com");
mailMessage.From = new MailAddress("saro17.ams#gmail.com");
mailMessage.Subject = "ASP.NET e-mail test";
mailMessage.Body = "Hello world,\n\nThis is an ASP.NET test e-mail!";
SmtpClient smtpClient = new SmtpClient("mail.feo.co.in");
smtpClient.Send(mailMessage);
Response.Write("E-mail sent!");
%>
I don't know why mail is not sending here.Please help me to fix this.
As per your JsFiddle, I found that there are so many silly mistakes in your HTML code.
Here is your ASP.NET code:-
<form id="form1" runat="server">
<div class="form-group">
<asp:TextBox ID="txtname" runat="server" CssClass="form-control"></asp:TextBox>
</div>
<div class="form-group">
<asp:TextBox ID="txtmobileno" runat="server" CssClass="form-control"></asp:TextBox>
</div>
<div class="form-group">
<asp:TextBox ID="txtEmail" runat="server" CssClass="form-control"></asp:TextBox>
</div>
<div class="form-group">
<asp:TextBox ID="txtSubject" runat="server" CssClass="form-control"></asp:TextBox>
</div>
<asp:Button ID="btnSubmit" runat="server" CssClass="btn btn-primary pull-right" OnClick="btnSubmit_OnClick" Width="100" Text="Submit" />
</form>
Code behind cs code
Created a SendMail() function which will fire on buttonclick
Note:- I haven't added validations on the controls, so if you want it you can add as per your requirement.
protected void SendMail()
{
// Gmail Address from where you send the mail
var fromAddress = "Gmail#gmail.com";
// any address where the email will be sending
var toAddress = txtEmail.Text.ToString();
//Password of your gmail address
const string fromPassword = "Your gmail password";
// Passing the values and make a email formate to display
string subject = txtSubject.Text.ToString();
// Passing the values and make a email formate to display
string body = "From: " + txtname.Text + "\n";
body += "Email: " + txtEmail.Text + "\n";
// smtp settings
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
// Passing values to smtp object
smtp.Send(fromAddress, toAddress, subject, body);
}
Now the above function will be called on Button click so that every time you enter the details you can call that function.
protected void btnSubmit_OnClick(object sender, EventArgs e)
{
try
{
SendMail(); // Send mail function to send your mail
txtname.Text = "";
txtEmail.Text = "";
txtmobileno.Text = "";
txtSubject.Text = "";
}
catch (Exception ex)
{
ex.Message.ToString();
}
}
For a detail explanation have a look at below link:-
http://www.codeproject.com/Tips/371417/Send-Mail-Contact-Form-using-ASP-NET-and-Csharp