Link to home
Start Free TrialLog in
Avatar of th34
th34

asked on

Capture value from action form

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>



Avatar of keystrokes
keystrokes
Flag of United States of America image

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.
Avatar of apollois
apollois

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.

Avatar of th34

ASKER

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.
Avatar of th34

ASKER

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?
Avatar of th34

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of gladxml
gladxml

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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.
Avatar of th34

ASKER

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.
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
th34,

Glad to be of helped...

Good on the rest of your project...

Happy programming...

Regards,
gladxml