Solved

Verify Form data, then submit

Posted on 2004-09-09
4
1,017 Views
Last Modified: 2008-01-09
When a user enters info into a Form, how would I verify the data and then submit the Form to another page that handles the data?

I need to have the form page open message boxes if the data the entered is incorrect and make the user try again, or if the data is correct, submit the form to another .asp page.

currently I just have this which just sends the form without checking the data:

<form name="form1" method="post" action="SendSuggestion.asp">

Thanks
0
Comment
Question by:mgcIT
[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 Comments
 
LVL 15

Assisted Solution

by:Colosseo
Colosseo earned 50 total points
ID: 12019676
Hi

One of if not the most common way to do this would be to use javascript

in your form you would change your submit button to a button and give it an onclick event like

<input type=button name=submit onclick="verifyAndSubmit()">

Then you would have a javascript function defined on your page to validate the form data

<script language="javascript">

  function verifyAndSubmit() {
    var f = document.form1;
   
    //an example of check
    if(f.txtfield.value==""){alert{'You must enter a value in the textfield');return false;}
   
    // submit the form if all validations pass
    f.submit();
  }
</script>

HTH

let me know if you want help with the validation

Scott
0
 
LVL 2

Assisted Solution

by:LinuxCluster
LinuxCluster earned 50 total points
ID: 12019684
Hi mgcIT,

you have too choices:

1) verify the data the user enters with the help of a JavaScript.
    + It checks the entered data immediately
    + It can pop up an alert box if soemthing is wrong
    - JavaScript needs to be activated
    - You will have to run multiple scripts for different types of fields (phone number, date, name etc.)

2) submit the form to an asp page that does error checking with the fields and if soemthing is not right, it can send the user back to the form page and display the according error messages. If everything is allright it will go to SendSuggestion.asp.
    + No JavaScript neccessary
    + You can write a function and reuse the different entry verifyers
    + You can design the error msg. with the website design
    - One extra step for the server to handle (but is minimal)
    - The user has to submit the form first, and then fix any mistakes

Depending on what solution you prefer we can give you the apropriate solution.

Regards,
LinuxCluster
0
 
LVL 15

Accepted Solution

by:
joeposter649 earned 50 total points
ID: 12019901
Don't use the onclick even as a form can be submitted sometimes by just hitting enter.
Use the onsubmit event of the form and be sure to return the result so it doesn't submit...
onsubmit="return validate()">

Have validate() return true if it's ok to submt and false if there were problems.

http://www.w3schools.com/js/tryit.asp?filename=tryjs_formvalidate
0
 
LVL 18

Author Comment

by:mgcIT
ID: 12020238
many thanks to everyone...
0

Featured Post

Independent Software Vendors: 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!

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…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 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