473,320 Members | 1,850 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Form Submit Problem

I have a small .aspx page that uses old style forms with client-side JavaScript validation. Everything works fine until I try to
upate the database with some new information. I must be doing something fundamentally wrong because I can't find any help on this
anywhere.

Here's my HTML form...

<form name="frmNewUser" onSubmit="return validateForm();">
<table>
<tr><td>User Name:</td><td><input id="iptUserName" type="text" size="20" /></td></tr>
<tr><td>E-mail Address:</td><td><input id="iptUserEmail" type="text" size="40" /></td></tr>
<tr><td colspan=2><input type="submit" value="Submit Details" /></td></tr>
</table>
</form>

Here's my client-side JavaScript validation...

function validateForm()
{
var userName = document.frmNewUser.iptUserName.value;
var userEmail = document.frmNewUser.iptUserEmail.value;

if(userName.length < 2 || userName.length > 15)
{
alert("The user name must be between 2 and 15 characters.");
return false;
}

if(userEmail.indexOf("@") == -1)
{
alert("You must enter a valid e-mail address.");
return false;
}

return true;
}

How do I get the values from the form in to my database?

--

Myk Quayce
www.quayce.freeserve.co.uk
"Whatever happened to all the fun in the world?" - Frank Zappa

Nov 18 '05 #1
2 1620
Your form doesn't have an ACTION or a METHOD attribute and so if it is an
"old style form" as you say, the data isn't going anywhere and therefore,
you can't retrieve it.
"Myk Quayce" <my*@quayce.freeserve.co.uk.spamless> wrote in message
news:br**********@newsg4.svr.pol.co.uk...
I have a small .aspx page that uses old style forms with client-side JavaScript validation. Everything works fine until I try to upate the database with some new information. I must be doing something fundamentally wrong because I can't find any help on this anywhere.

Here's my HTML form...

<form name="frmNewUser" onSubmit="return validateForm();">
<table>
<tr><td>User Name:</td><td><input id="iptUserName" type="text" size="20" /></td></tr> <tr><td>E-mail Address:</td><td><input id="iptUserEmail" type="text" size="40" /></td></tr> <tr><td colspan=2><input type="submit" value="Submit Details" /></td></tr> </table>
</form>

Here's my client-side JavaScript validation...

function validateForm()
{
var userName = document.frmNewUser.iptUserName.value;
var userEmail = document.frmNewUser.iptUserEmail.value;

if(userName.length < 2 || userName.length > 15)
{
alert("The user name must be between 2 and 15 characters.");
return false;
}

if(userEmail.indexOf("@") == -1)
{
alert("You must enter a valid e-mail address.");
return false;
}

return true;
}

How do I get the values from the form in to my database?

--

Myk Quayce
www.quayce.freeserve.co.uk
"Whatever happened to all the fun in the world?" - Frank Zappa

Nov 18 '05 #2
As this is an old-style form, you can't access the form elements the asp.net
way (eg. using controlname.Text). However, if you modify the form tag to
include the action and method attributes, so that is posts back to the same
page (action="mypage.aspx" method="post"), you should be able to access the
posted data using Request.Form.Get("iptUserName") and
Request.Form.Get("iptUserEmail") in the Page_Load event.

You might also want to add a hidden action field in the form, and check this
in the page load, to make sure that the postback is caused by your old-style
form and not the asp.net form. Once you have this data, you can the execute
the appropriate SQL to update your database.

Eg.

<form name="frmNewUser" action="newuser.aspx" method="post"
onSubmit="validateForm()">
<input name="action" type="hidden" value="newUserRegistration">
<!-- Standard stuff here, as specified below -->

In the code behind file:

private void Page_Load(object sender, System.EventArgs e)
{
// Get the action
string action = Request.Form.Get("action");

// Check the action
if (action == "newUserRegistration")
{
// Get posted values here
string username = Request.Form.Get("iptUserName").Trim();
string email = Request.Form.Get("iptUserEmail").Trim();

// Check they aren't blank, and/or other validation here
boolDataOK = ((username != string.Empty) && (email != string.Empty))
if (boolDataOK) updateData(username, email);
}
}

// Update the database
private void updateData(string username, string email)
{
// Use the username and email parameters here to update the DB
}
Hope this helps,

Mun


"Myk Quayce" <my*@quayce.freeserve.co.uk.spamless> wrote in message
news:br**********@newsg4.svr.pol.co.uk...
I have a small .aspx page that uses old style forms with client-side JavaScript validation. Everything works fine until I try to upate the database with some new information. I must be doing something fundamentally wrong because I can't find any help on this anywhere.

Here's my HTML form...

<form name="frmNewUser" onSubmit="return validateForm();">
<table>
<tr><td>User Name:</td><td><input id="iptUserName" type="text" size="20" /></td></tr> <tr><td>E-mail Address:</td><td><input id="iptUserEmail" type="text" size="40" /></td></tr> <tr><td colspan=2><input type="submit" value="Submit Details" /></td></tr> </table>
</form>

Here's my client-side JavaScript validation...

function validateForm()
{
var userName = document.frmNewUser.iptUserName.value;
var userEmail = document.frmNewUser.iptUserEmail.value;

if(userName.length < 2 || userName.length > 15)
{
alert("The user name must be between 2 and 15 characters.");
return false;
}

if(userEmail.indexOf("@") == -1)
{
alert("You must enter a valid e-mail address.");
return false;
}

return true;
}

How do I get the values from the form in to my database?

--

Myk Quayce
www.quayce.freeserve.co.uk
"Whatever happened to all the fun in the world?" - Frank Zappa

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: T.E. | last post by:
Hi all, I'm a newbie in php. I encounter a problem with php form that has only one textfield. If I click on the submit button, the form works fine. However, when I press 'enter', the form...
15
by: M Smith | last post by:
I have a form I want to submit to itself. I want to be able to type in a list of numbers and submit the form and have that list show up on the same form under the text box I typed them into and...
4
by: Stuart Perryman | last post by:
Hi, I have the following code which works just fine in IE6 but not in Firefox. It is an extract of several table rows each with an individual form. It is generated by php. <form...
5
by: rjames.clarke | last post by:
I have the following. $result=mysql_query($sql); $nrows=mysql_num_rows($result); for ($i=0;$i<$nrows;$i++) { $row_array=mysql_fetch_row($result); echo "<form name='testform'...
0
by: 42 | last post by:
I implemented a simple class inherited from Page to create a page template. It simply wraps some trivial html around the inherited page, and puts the inherited page into a form. The problem I...
4
by: Alex Sibilev | last post by:
Hello, I have a really weird problem I've been trying to solve it without any luck for the last couple of hours :( I'm writing a "conference board" application (quite similar to ASP.NET...
4
by: jwlum | last post by:
I have the following problem under Internet Explorer only: 1. User fills out form data (myform.php) and clicks a button that fires myFunction() 2. myFunction() spawns a "hello, world" popup page...
16
by: browntown | last post by:
so I have this application I'm nearly finished with. The only thing the client has requested is the ability to submit the form by pressing "enter". I didn't think this would be a huge pain in the...
4
by: Greg Scharlemann | last post by:
I'm trying to setup a dyamic dropdown list that displays a number of text fields based on the selected number in the dropdown. The problem I am running into is capturing the data already entered...
26
by: Jerim79 | last post by:
I need to create a form that takes a number that the user enters, and duplicates a question the number of times the user entered. For instance, if the customer enters 5 on the first page, when...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.