Solved

Verify Form data, then submit

Posted on 2004-09-09
4
998 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now