Anmelden | Registrieren | FAQ
Anonymous

Validate form and insert data in Database

+ Antwort erstellen

3 Beiträge Seite 1 von 1


Validate form and insert data in Database

von jackkds789 » Fr Okt 02, 2015 12:34 pm

Hey Guys,
let say a form consist of two text box , one is for username and other text box for email.Now I want to validate each one of them whether the name is not empty and email is in correct format.If they are in proper format then add into the database.

So can anyone please tell me how should i proceed with it?
Benutzeravatar

jackkds789

  • Beiträge: 6
  • Registriert: So Sep 27, 2015 6:26 pm

Re: Validate form and insert data in Database

von Farhin Qureshi » Mi Jan 11, 2017 12:08 pm

If you are using php with html then you can use the following:
Code: Alles auswählen
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <script type="text/javascript">

        //Client-side validation example
        function validate() {

            var fname = document.getElementById("fname");
            var lname = document.getElementById("lname");
            var email = document.getElementById("email");

            var emptyerror = "Please enter value"
            var erroremail = "please enter valid email address";

            if (fname.value == "" || fname.value == emptyerror) {
                fname.value = emptyerror
            }
            else {
                fname.value = "";
            }


            if (lname.value == "" || lname.value == emptyerror) {
                lname.value = emptyerror
            }
            else {
                lname.value = "";
            }

            if (email.value == "" || email.value == emptyerror) {
                email.value = emptyerror
            }
            else {
                email.value = "";
            }

            if (!(email.value == emptyerror || email.value == erroremail))
                if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.value)) {
                    email.classList.add("errordiv");
                    email.value = erroremail;
                }
        }
    </script>
</head>
<body>

    <h1>Trainee Registration Form </h1>
    <h3> First Name: <input id="fname" type="text" value="" name="name" class="required" /> </h3>
    <h3> Last Name: <input id="lname" type="text" value="" name="name" class="required" /> </h3>
    <h3> Email ID: <input id="email" type="text" value="" name="email" class="required" /> </h3>
    <input class="submit" type="button" name="submit" value="Submit" onclick="validate()" />
    <span id="result"></span>


</body>
</html>

Benutzeravatar

Farhin Qureshi

  • Beiträge: 45
  • Registriert: Di Jan 03, 2017 11:33 am
--
Farhin Qureshi
.NET Developer
http://www.ifourtechnolab.com

Re: Validate form and insert data in Database

von Regio » Mi Mai 03, 2017 11:26 am

I recommend to use php frameworks for this. there are any good simple systems on the market - e.g. the open source framework rexo.ch. here you find a solution to exactly what you want (username and password instaed of username and email).
Benutzeravatar

Regio

  • Beiträge: 1
  • Registriert: Mi Mai 03, 2017 11:19 am


+ Antwort erstellen

Seite 1 von 1