Solved

Verify Form data, then submit

Posted on 2004-09-09
4
1,011 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Select2 jquery help 9 100
VBScript on Html 15 57
Code Manager | Snippits 2 63
StoredProcedure to JSON query faulty syntax 2 26
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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…

749 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