Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 12th, 2004, 12:53 PM
Registered User
 
Join Date: Mar 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default New to ASP

I would be grateful if anyone could help me out with a problem I have relating to forms.

I have created an asp page that contains both the form and the feedback page so that if the user doesn't complete all of the fields then the form is bounced back with an error message adjacent to the field that is incorrect whilst leaving the correct fields completed. However I need to know how to check if it is the first time that the user is viewing the form - at the moment the form works fine if the user puts in either correct detail or some detail that is invalid but if they leave all of the boxes blank then the form can be submitted. I want the script to test if there is anything in each field and then give the user a message if they have not completed a section of the form but my script displays the "You have not completed this section" message on first loading the page. How can I get round this?

 
Old March 12th, 2004, 01:14 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

There are a few ways to check whether the form has been submitted or not. The easiest way is to check the value of the submit button:
Code:
<form bla bla bla>
  ...
  Other form controls
  ...
  <input type="submit" name="btnSubmit" id="btnSubmit" value="Send Feedback" />
</form>
This button has a name property, which you can check against in your ASP code:
Code:
<%
  If Request.Form("btnSumbit") <> "" Then
    ' Form has been submitted
  Else
    ' First time the page loads
  End If
%>
In addition to this, you could add client side JavaScript that prevents the form from being submitted when not all required fields have been filled in correctly. This saves you an additional roundtrip and increases the responsiveness of your application.

HtH,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old March 15th, 2004, 01:20 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Just a slight correction to Imar's post,

Then you test for this:

Request.Form("btnSumbit")

You are actually testing for the submit button's "value" attribute. You can have multiple submit buttons in the same form, but only the one that was clicked will post its value.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old March 17th, 2004, 04:56 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default

Hi

Just to add some stuff onto the previous posts.

What I normally use to avoid the msgboxes displaying on the first open and also check specific data in fields are something like this.

<SCRIPT LANGUAGE="VBSCRIPT">
<!--
Sub Send_onclick
If form.elements(0).value = "" Then
    XValue = form.elements(0).ID
    Alert "Please Complete the " & XValue & " " & "Field!"

        Else
                 form.submit
        End If
-->
</Script>
The Submit Button Looks like this
<input type="button" name="Send" value="Submit">
The form Look like this
<form name="form" method="post" action="Form.asp">

Regards
Marnus

Such is Life!
 
Old March 17th, 2004, 09:05 AM
Authorized User
 
Join Date: Mar 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to aliasp Send a message via Yahoo to aliasp
Default

hi,

if you make a validaty to form write that:
1-
<%
 ' check Blank textbox
 if request.form("xx")= "" then
   respons.redirect "aaa.asp" ' return to the source page
   else
   ......... 'complete your privet code
 end if
%>

OR

2-
 <%
 ' check Blank textbox
 if request.form("xx")= "" then
    response.write " Plz fill the textbox"
    response.end 'this code to stop run the program

  else
   ......... 'complete your privet code
 end if
%>

reg,

Ali


ali





Similar Threads
Thread Thread Starter Forum Replies Last Post
send parameters from asp page to an asp.net form hastikeyvan ASP.NET 1.0 and 1.1 Basics 2 March 29th, 2008 01:32 AM
using asp.net web user control in asp 3.0 App i_shahid Classic ASP Professional 0 January 8th, 2008 07:32 AM
Custom HTTP 404 Problem w/ASP to ASP.NET kwilliams ASP.NET 2.0 Professional 7 November 26th, 2007 04:17 PM
Upgrading ASP w/ SQLserver 2000 to ASP.NET w/2005 cJeffreywang ASP.NET 2.0 Basics 1 April 5th, 2007 11:30 PM
Porting a sa,ple ASP CR viewer app to ASP.NET jhansen42 Crystal Reports 0 August 29th, 2003 10:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.