?
Solved

Capture value from action form

Posted on 2003-02-20
11
Medium Priority
?
296 Views
Last Modified: 2012-06-27
I have a situation where I have an entry form that users fill out their address information.  I also have javascript that checks to make sure all of the required fields are filled.  If a required field is left blank, a message box pops up and the form does not get submitted.
If all of the required fields are filled out, it submits the form. All of this works well.  

My problem is this.  The validation works well on the client side but I also need to do the validation on the back end (in my stored procedure).  For now, lets put aside that I am doing the validation on the client side and that I am doing in all from the back end.  I have FORMA where users enter in address information and FORMB where I run my stored procedure to grab -1 or 0.

EXAMPLE:
<FORM NAME="FORMA" action="FORMB.asp" METHOD="POST">
First Name:       Last Name:
Submit button
</FORM>

<FORM NAME="FORMB" METHOD="POST">
-run my stored procedure to do validation.  
-It returns me -1(not all required fields are filled) and 0(all required fields are filled)
-I have an IF statement that checks for -1 or 0.  If -1, I have javascript that does "history.back(1);".  I want to keep what ever information the users filled out on FORMA.
-This is my problem:  I can't capture -1 value on FORMA until I refresh the form.  If I refresh the form, I loose what ever information the users enter in.  How can I keep the information the users enter in on FORMA and also capture the -1 value from FORMB????
</FORM>



0
Comment
Question by:th34
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
11 Comments
 
LVL 3

Expert Comment

by:keystrokes
ID: 7990049
Why are you checking on server side if you already validate it on the client side?  If you are trying to validate the same data before and after it's submitted at the same time, it's a logical error - it cannot be done.
0
 
LVL 10

Expert Comment

by:apollois
ID: 7990089
HOW TO MAKE SURE DATA IS ENTERED FOR ALL FORM TEXT BOXES


Basically all you need to do is test all text boxes.  If any one of them is blank, then set a flag.  If the flag is set, the output a message.

Here's an example.  You will need to fill in the details concerning your form, and form processing.  Let me know if you have any follow-up questions.

Best Regards,
apollois

==================================================================
<%
DIM bolFormBlank

bolFormBlank = False



'--- CHECK TO SEE IF FORM WAS SUBMITTED ---
'Note:  This is the best and easiest test since
'          it does NOT depend on the name of any FORM element

IF Request.form.count > 0 THEN

     '--- FORM WAS SUBMITTED ---

     '--- LOOP THRU ALL FORM ELEMENTS ---
     strBlankElem = ""
     FOR Each strElem in Request.Form
          IF Len(Request.Form(strElem)) = 0 THEN
               '--- Blank Form Elem found ---
               bolFormBlank = True
               strBlankElem = strBlankElem & strElem & ", "
          END IF
     NEXT
     iLen = Len(strBlankElem)
     IF iLen > 0 THEN
          strBlankElem = Left(strBlankElem, iLen - 2)
     END IF

     
     IF bolFormBlank THEN
          strMsg = "Please enter a value the following fields:" _
                         & "<BR>" & strBlankElem & "<BR><BR>"
     ELSE
          '--- FORM DATA VALIDATED ---
          strURL = "Confirm.asp"          'Your form confirmation page
          Response.Redirect strURL
     END IF

ELSE
     '--- FIRST TIME PAGE IS DISPLAYED ---
     strMsg = "Please enter a value for all fields"
END IF

%>
<HTML>
<BODY>
<!--- DISPLAY MESSAGE HERE --->
<%=strMsg%>

<!--- ENTER YOUR FORM HERE --->

</BODY>
</HTML>
====================================================

In order to initialize the FORM elements to the value entered by the user, use the following approach for text boxes:

<INPUT Name="Field1" Type="Text" Value="<%=Request.form("Field1")%>">

Replace "Field1" with the actual name of your field.

The first time through Request.form("Field1") will evaluate to an empty string ("").  You can do something similar with dropdowns, checkboxes, and radio buttons, but it's a little more work.

0
 

Author Comment

by:th34
ID: 7990212
keystrokes,

The reason I need to do validation on the back end also is in case the validation on the client side does not run.  I am double checking front and back.  We have one machine where IE6.0 does not run the javascript at all.  I want to do the validation on the back end so that a record does not get added to the table if the users does not fill all of the required fields.  If I don't check on the back end, the stored procedure adds a blank record to the table and it's not what I want.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:th34
ID: 7990261
apollois,

What I really want is to use javascript to do the front end validation (they like the pop up message) and use stored procedure to do the validation on the back end.  The reason I want to do the validation on the back end is because we came across a machine with IE6.0 where it did not run the javascript and it added a blank record to the table.  I want to prevent a blank record from adding to the table and inform the users that not all of the required fields were filled.  Is it not possible?
0
 

Author Comment

by:th34
ID: 7990283
apollois,

What I really want is to use javascript to do the front end validation (they like the pop up message) and use stored procedure to do the validation on the back end.  The reason I want to do the validation on the back end is because we came across a machine with IE6.0 where it did not run the javascript and it added a blank record to the table.  I want to prevent a blank record from adding to the table and inform the users that not all of the required fields were filled.  Is it not possible?
0
 
LVL 15

Accepted Solution

by:
gladxml earned 200 total points
ID: 7990751
th34,

Try to check the link below...

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20410682.html

The question has a html code with client side validation

BTw save it as gladx.asp


Now you as you can see the page pass the form to itself

Inside the if statement you can put the serverside validation..

<%

if request.form("form_ok")="True" then

response.write request.form("textfield6") & "<br>"
response.write request.form("textfield5") & "<br>"
response.write request.form("ccType") & "<br>"
response.write request.form("ccNum") & "<br>"

end if

%>

Also this way you dont need to put any history.back you just need to post the original html code if there are error encounter... You can try something like this...


<%

if request.form("form_ok")="True" then

if noerror then

'update
'insert
'response.redirect

else

'your error message that you can post to load the page again...

end if

end if

%>


Hope this help...

HAppy programming...

0
 
LVL 4

Expert Comment

by:whammy
ID: 7990858
P.S. Of course, you're right th34, and keystrokes is wrong - you should always validate server-side, even if you're using client-side javascript validation to conserve server resources.

Very few clients will have javascript disabled, but you don't want your application to break when that is the case.

And it's NOT a "logical error" to validate on the client-side AND the server-side (it's a VERY GOOD idea, actually), I'm not sure where keystrokes got this idea, but it is completely erroneous.
0
 
LVL 4

Expert Comment

by:whammy
ID: 7990889
P.S. From a cursory look at his replies it seems like gladxml uses the same kind of progamming logic I use in classic ASP...

post the form to itself and do all of your validation in the same spot, and display different subroutines depending upon whatever was entered by the user.

I find that the easiest way to validate forms in classic ASP, using logic I learned from BASIC.
0
 

Author Comment

by:th34
ID: 7994855
gladxml,
I used the example you suggested and it works well.  I knew there had to be a way for what I wanted to do.  Thank you sooooooooo much for your help.

apollois,
I used your suggestion to write back the value after the users submit the form "<INPUT Name="Field1" Type="Text" Value="<%=Request.form("Field1")%>">" and it works.  I can't thank you enough for your help.  I don't know how to give you 50 points also.  I can only accept one answer and gladxml paved the road for me and it's only fair that I give him the points.  If there is a way that I can give you 50 points, email me and I would be glad to give it to you too.

whammy,
Thank you for your input.  You are right about doing validation on client and server side.  I learned the hard way.  It's a mistake that I will never make again.
0
 
LVL 10

Expert Comment

by:apollois
ID: 7995497
th34,

I'm glad you're problem is solved.

>>>If there is a way that I can give you 50 points, email me and I would be glad to give it to you too. <<<

Thanks, that's very kind of you.

Easy enough to do.  Just post another question in the ASP TA with the title "Points for Apollois".  I'll answer, and you can accept.

Best Regards,
apollois
0
 
LVL 15

Expert Comment

by:gladxml
ID: 7996164
th34,

Glad to be of helped...

Good on the rest of your project...

Happy programming...

Regards,
gladxml
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question