Solved

Verify Form data, then submit

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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