Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Php - bootstrap form validation and submit function help!

dadadaxtr

Novice
Advanced Member
Messages
46
Reaction score
1
Points
28
Tanong ko lang po? Bakit ang form ko di gumagana ang submit button once na gumamit ang ng form validation ng bootstrap template ko? dba pag usual na code lang
yung "process/user-add.php" yan po yung separated file ko para sa process ng pag insert.
Code:
<div class="modal-body">
								  <form  method="post"  action="process/user-add.php" id="validate" >
									<div class="row">
										<div class="col-lg-1"></div>
										<div class="col-lg-5">
											<div class="form-group">
												<label class="control-label">User name
												<span class="required">*</span>
												</label>
												<input class="form-control" type="text" name="user_name" placeholder="User name" required>
											</div>
											<div class="form-group">
												<label class="control-label">Password
												<span class="required">*</span>
												</label>
												<input class="form-control" type="password" name="password" placeholder="Password" required>
											</div>
											<div class="form-group">
												<label class="control-label">First name
												<span class="required">*</span>
												</label>
												<input class="form-control" type="text" name="first_name" placeholder="First name" required>
											</div>
											<div class="form-group">
												<label class="control-label">Last name
												<span class="required">*</span>
												</label>
												<input class="form-control" type="text" name="last_name" placeholder="Last name" required>
											</div>
											<div class="form-group">
												<label class="control-label">E-mail
												<span class="required">*</span>
												</label>
												<input class="form-control" type="email" name="email" placeholder="E-mail" required>
											</div>
										</div>
										<div class="col-lg-5">
											<div class="form-group">
												<label class="control-label">Gender
												<span class="required">*</span>
												</label><br>
												<input type="radio" name="gender"checked="checked" value="Male"> Male 
												<input type="radio" name="gender" value="Female"> Female
											</div>
											<div class="form-group">
												<label class="control-label">Birthday
												<span class="required">*</span>
												</label>
												<input class="form-control" type="date" name="birthday" placeholder="YYYY-MM-DD" required>
											</div>
											<div class="form-group">
												<label class="control-label">Address
												<span class="required">*</span>
												</label>
												<textarea name="address" class="form-control" COLS=40 ROWS=6 placeholder="Address" required></textarea>
											</div>
										</div>
										<div class="col-lg-1"></div>
									</div>
							</div>
							<div class="modal-footer">
								<button type="submit" id="submit" name="submit" class="btn btn-success"><i class="fa fa-plus"></i> Add</button>
								</form>


YAN po yung code ko sa form.. then ito naman SCRIPT

Code:
<script>
    $(document).ready(function($) {
      Site.run();
	  $('#submit').click(function(){
		  
	  });
	  
	     // Example Validataion Standard Mode
      // ---------------------------------
      (function() {
        $('#validate').formValidation({
          framework: "bootstrap",
          fields: {
            user_name: {
             validators: {
                notEmpty: {
                  message: 'The username is required'
                },
                stringLength: {
                  min: 6
                },
                regexp: {
                  regexp: /^[a-zA-Z0-9]+$/
                }
              }
            },
			password: {
              validators: {
                notEmpty: {
                  message: 'The password is required and cannot be empty'
                },
                stringLength: {
                  min: 8
                }
              }
            },
			first_name: {
              validators: {
                notEmpty: {
                  message: 'The full name is required and cannot be empty'
                },
				regexp: {
                  regexp: /^[a-zA-Z]+$/
                }
              }
            },
			last_name: {
              validators: {
                notEmpty: {
                  message: 'The last name is required and cannot be empty'
                },
				regexp: {
                  regexp: /^[a-zA-Z]+$/
                }
              }
            },
            email: {
              validators: {
                notEmpty: {
                  message: 'The email address is required and cannot be empty'
                },
                emailAddress: {
                  message: 'The email address is not valid'
                }
              }
            },
			gender: {
              validators: {
                notEmpty: {
                  message: 'The gender is required and cannot be empty'
                }
              }
            },
			birthday: {
              validators: {
                notEmpty: {
                  message: 'The birthdate is required and cannot be empty'
                },
                regexp: {
                  regexp: /^[0-9-]+$/
                }
              }
            },
            address: {
              validators: {
                notEmpty: {
                  message: 'The andress is required and cannot be empty'
                },
                stringLength: {
                  max: 50,
                  message: 'The address must be less than 50 characters long'
                }
              }
            }
          }
        });
      })();
    });
  </script>
 
pag click mo ng submit button, may response ba? may error ba sa console? kung meron ano ung error?
 
baka hindi mu na change yung id name ng button ? gagana kasi am validation once na magmatch am id sa js na file .
 
sir, i'm not sure but yung submit button mo ay walang laman na code. wala siyang ma execute.

try mo nga ganitong style sir.

function validate(){
//lagay mo ang code mo sa validation dito
}

tapos sa button submit mo.

$("#submit").click(function(){
validate();
});
 
sir, i'm not sure but yung submit button mo ay walang laman na code. Wala siyang ma execute.

Try mo nga ganitong style sir.

Function validate(){
//lagay mo ang code mo sa validation dito
}

tapos sa button submit mo.

$("#submit").click(function(){
validate();
});

actually mga sir gumagana po code ko... Ang problem ko lang jan is nung gumamit ako ng form validation ng bootstrap at nag add ako ng id sa may form. Di na gumana submit button ko. Pero kung alisin ko yung idea.. Working naman po yung code ko. Confuse lang ako pano ba gumamit ng function sa jquery para ma path dun sa process file ko?
 
actually mga sir gumagana po code ko... Ang problem ko lang jan is nung gumamit ako ng form validation ng bootstrap at nag add ako ng id sa may form. Di na gumana submit button ko. Pero kung alisin ko yung idea.. Working naman po yung code ko. Confuse lang ako pano ba gumamit ng function sa jquery para ma path dun sa process file ko?

Kung aalisin ung JS,jQuery ggana yan. pero sa tingin kaya d gana yan kc dapat bwat fields ay may id and then from that id tawagin mo sa JS

ex. <input type='text' id='username'> //HTML

function Username()
{
var username = document.getElementById("username").value;
if(username =='')
{
alert("username is empty");
}
}


suggest ko nalng is gawa ka nalng ng sariling Form Validation using JS then Ajax para e send ung data sa PHP function mas madali pa at hindi mahirap

ex. //sa script to

function SaveNewUser()
{
var id = document.getElementById("id").value;
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;

if(id == '' || username=='' || password == '')
{
alert("Some fields is empty");
}else{

$.ajax({
type:'post',
url:'yourphpfuntionhere.php',
data:{
//ung e ssend mong data sa PHP function
},
success:function(savedata){

alert(savedata);

}

});

}

}
 
Back
Top Bottom