|
 |
|
Tutorialized Forums
> Web Design & Development
> ASP.NET
|
Registration Not Working!
Discuss Registration Not Working! in the ASP.NET forum on Tutorialized. Registration Not Working! ASP.NET forum covering the power of ASP with .NET combined, allowing the creation of web pages and dynamic web applications with less code. In addition, discuss the ability to create applications in .NET compatible languages such as C#.
|
|
 |
|
|
|

Tutorialized Forums Sponsor:
|
|

April 2nd, 2013, 01:44 PM
|
Registered User
|
|
Join Date: Apr 2013
Posts: 1
Time spent in forums: 4 m 5 sec
Reputation Power: 0
|
|
Registration Not Working!
Hey everyone,
I am new to ASP.NET and I am trying to make a registration form. While I am writing the code there are no errors showing up in WebMatrix but when I run the code the error messages are showing up next to the textboxes before I even click submit. When I click submit, nothing happens. I need to have two checkboxes, one for terms of service and another for the mailing list. But I do not know how to make ASP put the value from the checkbox into a database. I also need to have the country and state field have values in a drop down list, (the values coming from a XML source) and get validated and go into a database. But as of right now I need thiss registration to work!! Any Help would be appreciated! Thanks!
Code:
@section Scripts {
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
}
@{
Page.Title = "Register";
// Initialize General Page Variables
var firstName = "";
var middleInitial = "";
var lastName = "";
var streetAddress = "";
var streetAddressTwo = "";
var city = "";
var state = "";
var zipCode = "";
var country = "";
var phoneNumber = "";
var mobilePhone = "";
var faxPhone = "";
var email = "";
var password = "";
var confirmPassword = "";
var mailingList = Request["mailingList"]=="off"?true:false;
var TermsService = Request["TermsService"]=="on"?true:false;
// Setup Validation
Validation.RequireField("firstName", "You must specify a first name.");
Validation.RequireField("lastName", "You must specify a last name.");
Validation.RequireField("streetAddress", "You must specify a streetAddress.");
Validation.RequireField("city", "You must specify a city.");
Validation.RequireField("state", "You must specify a state.");
Validation.RequireField("zipCode", "You must specify a zip code.");
Validation.RequireField("country", "You must specify a country.");
Validation.RequireField("phoneNumber", "You must specify a phone number.");
Validation.RequireField("email", "You must specify your email address.");
Validation.RequireField("password", "Password cannot be blank.");
Validation.Add("confirmPassword",
Validator.EqualsTo("password", "Passwords do not match."));
Validation.Add("password",
Validator.StringLength(
maxLength: Int32.MaxValue,
minLength: 6,
errorMessage: "Password must be at least 6 characters long."));
Validation.RequireField("TermsService", "You must accept the Terms of Service and Privacy Policy Agreement.");
// If this is a POST request, Validate and process data
if (IsPost) {
AntiForgery.Validate();
firstName = Request.Form["firstName"];
middleInitial = Request.Form["middleInitial"];
lastName = Request.Form["lastName"];
streetAddress = Request.Form["streetAddress"];
streetAddressTwo = Request.Form["streetAddressTwo"];
city = Request.Form["city"];
state = Request.Form["state"];
zipCode = Request.Form["zipCode"];
country = Request.Form["country"];
phoneNumber = Request.Form["phoneNumber"];
mobilePhone = Request.Form["mobilePhone"];
faxPhone = Request.Form["faxPhone"];
email = Request.Form["email"];
password = Request.Form["password"];
confirmPassword = Request.Form["confirmPassword"];
mailingList = Request["mailingList"]=="on"?true:false;
TermsService = Request["TermsService"]=="off"?true:false;
// Validate the user's captcha answer
// if(Recaptcha.Validate("6Lec-t4SAAAAALBYv9CcfvQ7cj7ov9nG18td1SXB")) {
// ModelState.AddError("recaptcha", "Captcha response was not correct. Please try again.");
}
// If all information is valid, create a new account
if (Validation.IsValid()) {
// Insert a new user into the database
var db = Database.Open("StarterSite");
var ml = Database.Open("MailingList");
// Check if the user already exists.
var user = db.QuerySingle("SELECT Email FROM UserProfile WHERE LOWER(Email) = LOWER(15)", email);
if (user == null) {
// Insert email into the profile table
db.Execute("INSERT INTO UserProfile (firstName) VALUES (1)", firstName);
db.Execute("INSERT INTO UserProfile (middleInitial) VALUES (2)", middleInitial);
db.Execute("INSERT INTO UserProfile (lastName) VALUES (3)", lastName);
db.Execute("INSERT INTO UserProfile (streetAddress) VALUES (4)", streetAddress);
db.Execute("INSERT INTO UserProfile (streetAddressTwo) VALUES (5)", streetAddressTwo);
db.Execute("INSERT INTO UserProfile (city) VALUES (6)", city);
db.Execute("INSERT INTO UserProfile (state) VALUES (7)", state);
db.Execute("INSERT INTO UserProfile (zipCode) VALUES (8)", zipCode);
db.Execute("INSERT INTO UserProfile (country) VALUES (9)", country);
db.Execute("INSERT INTO UserProfile (phoneNumber) VALUES (10)", phoneNumber);
db.Execute("INSERT INTO UserProfile (mobilePhone) VALUES (11)", mobilePhone);
db.Execute("INSERT INTO UserProfile (faxPhone) VALUES (12)", faxPhone);
db.Execute("INSERT INTO UserProfile (Email) VALUES (15)", email);
// Create and associate a new entry in the membership database.
//If successful, continue processing the request.
try {
bool requireEmailConfirmation = !WebMail.SmtpServer.IsEmpty();
var token = WebSecurity.CreateAccount(email, password, requireEmailConfirmation);
if (requireEmailConfirmation) {
var hostUrl = Request.Url.GetComponents(UriComponents.SchemeAndS erver, UriFormat.Unescaped);
var confirmationUrl = hostUrl + VirtualPathUtility.ToAbsolute("~/Account/Confirm?confirmationCode=" + HttpUtility.UrlEncode(token));
WebMail.Send(
to: email,
subject: "Please confirm your Adk Title Account",
body: "Your confirmation code is: " + token + ". Visit <a href=\"" + confirmationUrl + "</a> to activate your account."
);
}
if (requireEmailConfirmation) {
//Thank the user for registering and let them know an email is on its way.
Response.Redirect("~/Account/Thanks");
} else {
//Navigate back to the homepage and exit
WebSecurity.Login(email, password);
Response.Redirect("/");
}
} catch
(System.Web.Security.MembershipCreateUserException e) {
ModelState.AddFormError (e.Message);
}
} else {
// User already exists
ModelState.AddFormError("Email address is already in use.");
}
}
}
}
<!DOCTYPE html>
<html>
<head>
<title>@Page.Title</title>
<link rel="stylesheet" type="text/css" href="~/Content/sliderbutton.css">
<link rel="stylesheet" type="text/css" href="~/Content/TermsStyle.css">
<link rel="stylesheet" type="text/css" href="~/Content/datepicker.css">
</head>
<body>
<form method="post">
@AntiForgery.GetHtml()
@* If at least one validation error exists, notify the user *@
@Html.ValidationSummary("Account create was unsuccessful. Please correct the errors and try again.", excludeFieldErrors: true, htmlAttributes: null)
<fieldset>
<legend>Registration Form</legend>
<ol>
<li class="firstName">
<label for="firstName" @if(!ModelState.IsValidField("firstName")) {<text>class="error-label"</text>}>First Name:*</label>
<input type="text" id="firstName" name="firstName" value="@firstName" @Validation.For("firstName") />
@Html.ValidationMessage("firstName")
</li>
<li class="middleInitial">
<label for="middleInitial" @if(!ModelState.IsValidField("middleInitial")) {<text>class="error-label"</text>}>Middle Initial:</label>
<input type="text" id="middleInitial" name="middleInitial" value="@middleInitial" />
</li>
<li class="lastName">
<label for="lastName" @if(!ModelState.IsValidField("lastName")) {<text>class="error-label"</text>}>Last Name:*</label>
<input type="text" id="lastName" name="lastName" value="@lastName" @Validation.For("lastName") />
@Html.ValidationMessage("lastName")
</li>
<li class="streetAddress">
<label for="streetAddress" @if(!ModelState.IsValidField("streetAddress")) {<text>class="error-label"</text>}>Street Address:*</label>
<input type="text" id="streetAddress" name="streetAddress" value="@streetAddress" @Validation.For("streetAddress") />
@Html.ValidationMessage("streetAddress")
</li>
<li class="streetAddressTwo">
<label for="streetAddressTwo" @if(!ModelState.IsValidField("streetAddressTwo")){<text>class="error-label"</text>}>Second Address:</label>
<input type="text" id="streetAddressTwo" name="streetAddressTwo" value="@streetAddressTwo" />
</li>
<li class="city">
<label for="city" @if(!ModelState.IsValidField("city")){<text>class="error-label"</text>}>City:*</label>
<input type="text" id="city" name="city" value="@city" @Validation.For("city") />
@Html.ValidationMessage("city")
</li>
<li class="state">
<label for="state" @if(!ModelState.IsValidField("state")) {<text>class="error-label"</text>}>State:*</label>
<input type="text" id="state" name="state" value="@state" @Validation.For("state") />
@Html.ValidationMessage("state")
</li>
<li class="zipCode">
<label for="zipCode" @if(!ModelState.IsValidField("zipCode")) {<text>class="error-label"</text>}>Zip Code:*</label>
<input type="text" id="zipCode" name="zipCode" value="@zipCode" @Validation.For("zipCode") />
@Html.ValidationMessage("zipCode")
</li>
<li class="country">
<label for="country" @if(!ModelState.IsValidField("country")) {<text>class="error-label"</text>}>Country:*</label>
<input type="text" id="country" name="country" value="@country" @Validation.For("country") />
@Html.ValidationMessage("country")
</li>
<li class="phoneNumber">
<label for="phoneNumber" @if(!ModelState.IsValidField("phoneNumber")){<text>class="error-label"</text>}>Home Phone:*</label>
<input type="tel" id="phoneNumber" name="mobilePhone" value="@phoneNumber" @Validation.For("phoneNumber") />
@Html.ValidationMessage("phoneNumber")
</li>
<li class="mobilePhone">
<label for="mobilePhone" @if(!ModelState.IsValidField("mobilePhone")){<text>class="error-label"</text>}>Mobile Phone:</label>
<input type="tel" id="mobilePhone" name="mobilePhone" value="@mobilePhone" />
</li>
<li class="faxPhone">
<label for="faxPhone" @if(!ModelState.IsValidField("faxPhone")){<text>class="error-label"</text>}>Fax Phone:</label>
<input type="tel" id="faxPhone" name="faxPhone" value="@faxPhone" />
</li>
<li class="email">
<label for="email" @if (!ModelState.IsValidField("email"))
{<text>class="error-label"</text>}>
Email Address:*</label>
<input type="email" id="email" name="email" value="@email"
@Validation.For("email") />
@* Write any email validation errors to the page *@
@Html.ValidationMessage("email")
</li>
<li class="password">
<label for="password" @if(!ModelState.IsValidField("password")){<text>class="error-label"</text>}>Password:*</label>
<input type="password" id="password" name="password" @Validation.For("password") />
@* Write any password Validation errors to the page *@
@Html.ValidationMessage("password")
</li>
<li class="confirm-password">
<label for="confirmPassword" @if(!ModelState.IsValidField("confirmPassword")){<text>class="error-label"</text>}>Confirm Password:*</label>
<input type="password" id="confirmPassword" name="confirmPassword" @Validation.For("confirmPassword") />
@* Write any password validation errors to the page *@
@Html.ValidationMessage("confirmPassword")
</li>
<li class="recaptcha">
<div class="recaptcha">
</div>
@*Recaptcha.GetHtml("6Lec-t4SAAAAAOlf-9lr8Uhz7sYgKJ46O5yWY_aw", theme: "white")
@Html.ValidationMessage("recaptcha")
*@
</li>
</ol>
<input type="submit" value="Register" />
</fieldset>
</form>
</body>
</html>
|

May 4th, 2013, 08:47 AM
|
Registered User
|
|
Join Date: Apr 2013
Posts: 22
Time spent in forums: 4 h 23 m 59 sec
Reputation Power: 0
|
|
Are there are any javascripts within your code ?
|
Developer Shed Advertisers and Affiliates
Thread Tools |
Search this Thread |
|
|
Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|