Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

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>



0
th34
Asked:
th34
  • 4
  • 2
  • 2
  • +2
1 Solution
 
keystrokesCommented:
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
 
apolloisCommented:
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
 
th34Author Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
th34Author Commented:
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
 
th34Author Commented:
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
 
gladxmlCommented:
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
 
whammyCommented:
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
 
whammyCommented:
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
 
th34Author Commented:
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
 
apolloisCommented:
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
 
gladxmlCommented:
th34,

Glad to be of helped...

Good on the rest of your project...

Happy programming...

Regards,
gladxml
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now