简体   繁体   中英

PHP - How Do I Create Multiple Form Fields Based On Selection Using Php with validation

I am create the simple with the validation. I have the field like firstname,Mobileno,city,email and add more option(selection).

I need to put validation and if mobile no already exist throw the error message. how can i put the validation.

<html>
<head>
<title>Show Multiple Form Using Drop down Option - Demo Preview</title>
<meta name="robots" content="noindex, nofollow" />
<!-- importing font family from google fonts -->
<link href='http://fonts.googleapis.com/css?family=Droid+Serif' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="multipleform.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/multipleform.js"></script>
</head> 
<body> 
<div class ="container">
<h2>Dynamically Created Form Fields Based On Selection</h2>
<div id="selected_form_code">
 <select id="select_btn">
 <option value="0">--Select No Of Form to Display for Registration--</option>
 <option value="1">One</option>
 <option value="2">Two</option>
 <option value="3">Three</option>
 <option value="4">Four</option>
 <option value="5">Five</option>
 </select>
 </div>
    <div id="form1">    
        <form id="form_submit" action="#" method="post">
         <!-- dynamic Registration Form Fields Creates here-->
        </form>
    </div> 
<!------ right side advertisement div ----------------->

</div>
</body>
</html>

My Js file is here

$(document).ready(function(){

     $('select#select_btn').change(function(){

    var sel_value = $('option:selected').val();
    if(sel_value==0)
    {
        //Resetting Form 
        $("#form_submit").empty();
        $("#form1").css({'display':'none'});
    }
    else{
        //Resetting Form 
        $("#form_submit").empty();

        //Below Function Creates Input Fields Dynamically 
        create(sel_value);

        //appending submit button to form
        $("#form_submit").append(
        $("<input/>",{type:'submit', value:'Register'})
        )
        }   
    }); 

function create(sel_value){
   for(var i=1;i<=sel_value;i++)   
       {
       $("div#form1").slideDown('slow');

        $("div#form1").append(
        $("#form_submit").append(
        $("<div/>",{id:'head'}).append(
        $("<h3/>").text("Registration Form"+i)),
        $("<input/>", {type:'text', placeholder:'Name'+i, name:'name_'+i}),
        $("<br/>"),
        $("<input/>", {type:'text', placeholder:'Email'+i, name:'email_'+i}),
        $("<br/>"),
        $("<textarea/>", {placeholder:'Mobile'+i, type:'text', name:'Mobile'+i}),
        $("<br/>"),     
        $("<hr/>"),
        $("<br/>")
                     ))
        }

    }


});

How to put validation for the mobile no and email id. Check the mobile no duplication.

If you can create multiple fields on form . you can write use j query and append any filed with proper format also you can use ajax and submit form without loading and result get on same page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM