i am creating a registration page and I want to autofill the the value of certain input field whenever i choose a specific department like .when i choose the department A . it will autofill who is the supervisor on that department on my registration .how do i do it ?
this is my html view code
<?php if (validation_errors()) { ?>
<div class="alert alert-danger" role="alert">
<center><span class="glyphicon glyphicon-alert" aria-hidden="true"></span><strong> Error!</strong><p><?= validation_errors(); } ?></p></center>
</div>
<?php if (isset($error)){ ?>
<div class="alert alert-danger" role="alert">
<center><span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span><strong> Error! </strong><?= $error ?> </center>
</div>
<?php } ?>
<div class="container-fluid">
<center> <h2>Register</h2></center>
<hr class="colorgraph">
<form class="form-horizontal" action="<?= base_url().'login/registeruser' ?>" method="post">
<div class="form-group">
<label for="username" class="col-sm-2 control-label "><?php if(form_error('username')){ echo '<p style="color:#a94442"> * Username </p>';} else { echo 'Username'; } ?></label>
<div class="col-sm-6">
<input type="text" class="form-control <?php if (form_error('username')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="username" name="username" placeholder="Username" value="<?php echo set_value('username'); ?>">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label "><?php if(form_error('password')||form_error('confpassword')){ echo '<p style="color:#a94442"> * Password </p>';} else { echo 'Password'; } ?></label>
<div class="col-sm-6">
<input type="password" class="form-control <?php if (form_error('password')||form_error('confpassword')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="password" name="password" placeholder="Password">
</div>
</div>
<div class="form-group">
<label for="confpassword" class="col-sm-2 control-label"><?php if(form_error('password')||form_error('confpassword')){ echo '<p style="color:#a94442"> * Confirm Password </p>';} else { echo 'Confirm Password'; } ?></label>
<div class="col-sm-6">
<input type="password" class="form-control <?php if (form_error('password')||form_error('confpassword')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="confpassword" name="confpassword" placeholder="Confirm Password">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label "><?php if(form_error('email')){
echo '<p style="color:#a94442"> * Email </p>';} else { echo 'Email'; } ?></label>
<div class="col-sm-6">
<input type="email" class="form-control <?php if (form_error('email')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="email" name="email" placeholder="Email"
value="<?php echo set_value('email'); ?>">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label"><?php if(form_error('fname')||form_error('mname')||form_error('lname')){ echo '<p style="color:#a94442"> * Full Name </p>';} else { echo 'Full Name'; } ?></label>
<div class="col-sm-2">
<input type="text" class="form-control <?php if (form_error('fname')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="fname" name="fname" placeholder="First Name" value="<?php echo set_value('fname'); ?>">
</div>
<div class="col-sm-2">
<input type="text" value ="sa" class="form-control <?php if (form_error('mname')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="mname" name="mname" placeholder="Middle Name" value="<?php echo set_value('mname'); ?>">
</div>
<div class="col-sm-2">
<input type="text" class="form-control <?php if (form_error('lname')) { echo
'alert alert-danger'.'"style="color:#000000'; } ?>" id="lname" name="lname" placeholder="Last Name" value="<?php echo set_value('lname'); ?>">
</div>
</div>
<div class="form-group">
<label for="gender" class="col-sm-2 control-label ">Gender</label>
<label class="radio-inline col-sm-1 control-label">
<input type="radio" name="gender" id="gender" value="M" selected="selected"> Male
</label>
<label class="radio-inline">
<input type="radio" name="gender" id="gender" value="F"> Female
</label>
</div>
<div class="form-group">
<label for="gender" class="col-sm-2 control-label ">Department</label>
<select name="Department">
<option value="stem">STEM</option>
<option value="gas">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
</div>
<div class="form-group">
<div class="col-sm-4 control-label">
<h3><strong>
Captcha
<?=$image; ?></strong></h3>
<input type="text" id="captcha" name="captcha" height="50px" autocomplete="off" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" class="btn btn-default"><span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span> Back</button>
<button type="submit" class="btn btn-primary">Register</button>
</div>
</div>
</form>
</div>
</body>
i want to specifically use php code .how do i do it ? thanks
You can use jquery ajax functionality for the same.
Related
When I add an additional field to my query, it fails. I have checked the spelling 20 or more times....I do not know what is wrong.. Please help!!
Working code BELOW
if(isset($_POST['UPDATE_RAW'])) {
extract($_POST);
$sql=mysqli_query($db,"update nma_raw set NMA_System='$nmasystem',NMA_Ticket_Number='$nmaticketnum',Tkt_Priority='$tktpriority',Created_On_Worklist='$createdonworklist',Create_Date='$createdate',Create_Time='$createtime',Days_Old='$daysold',Interval_Onlist='$intervalonlist',Check_Status='$checkstatus',Ticket_Status='$ticketstatus',Relate_Status='$relatestatus',WFA_TR_Num='$wfatrnum',Recent_WFA_Dispatch_Status='$recentwfadispatchstatus',Last_Owner='$lastowner',Entity_Status='$entitystatus',Entity='$entity',First_Cond_Type='$firstcondtype',Last_Cond_Type='$lastcondtype',State='$st',CLLI='$clli',Check_Active='$checkactive',Check_Jepd='$checkjepd' WHERE ID='$id'");
if($sql) {
echo "<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else {
echo "<script>alert('Some ERRORS');</script>";
}
}
NOT WORKING CODE BELOW!
if(isset($_POST['UPDATE_RAW'])) {
extract($_POST);
$sql = mysqli_query($db,"update nma_raw set NMA_System='$nmasystem',NMA_Ticket_Number='$nmaticketnum',Tkt_Priority='$tktpriority',Created_On_Worklist='$createdonworklist',Create_Date='$createdate',Create_Time='$createtime',Days_Old='$daysold',Interval_Onlist='$intervalonlist',Check_Status='$checkstatus',Ticket_Status='$ticketstatus',Relate_Status='$relatestatus',WFA_TR_Num='$wfatrnum',Recent_WFA_Dispatch_Status='$recentwfadispatchstatus',Last_Owner='$lastowner',Entity_Status='$entitystatus',Entity='$entity',First_Cond_Type='$firstcondtype',Last_Cond_Type='$lastcondtype',State='$st',CLLI='$clli',Check_Active='$checkactive',Check_Jepd='$checkjepd', Resolved_Date='$resolved_date' WHERE ID='$id'");
if($sql) {
echo "<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else {
echo "<script>alert('Some ERRORS');</script>";
}
}
HERE IS A PICTURE OF MY DB SCHEMA
enter image description here
HERE IS THE TOTAL PHP FILE
<?php include_once "header.php";?>
<section class="content">
<div class="page-body clearfix">
<?php
$id=$_REQUEST['id'];
$sql=mysqli_query($db,"SELECT NMA_RAW.*, NMA_RAW.Check_Status, NMA_RAW.Resolved_Date, NMA_RAW.Filtered_Date FROM NMA_RAW WHERE (((NMA_RAW.Check_Status)='OK') AND ((NMA_RAW.Resolved_Date) Is Null) AND ((NMA_RAW.Filtered_Date) Is Null)) AND NMA_RAW.ID = $id;");
$row = mysqli_fetch_array($sql);
?>
<div class="panel panel-default">
<div class="panel-heading">NMA Active Ticket Form</div>
<div class="panel-body">
<form class="form-horizontal" action="" method="post">
<div class="form-group">
<div class="col-sm-4">
<label>NMA System</label>
<input type="text" id="nma_system" class="form-control" placeholder="NMA System" value="<?= $row['NMA_System']; ?>" name="nmasystem">
</div>
<div class="col-sm-4">
<label>NMA Ticket Number</label>
<input type="text" id="nma_ticket_number" class="form-control" placeholder="NMA Ticket Number" value="<?= $row['NMA_Ticket_Number']; ?>" name="nmaticketnum">
</div>
<div class="col-sm-4">
<label>Ticket Priority</label>
<input type="text" id="ticket_priority" class="form-control" placeholder="Ticket Priority" value="<?= $row['Tkt_Priority']; ?>" name="tktpriority">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Created On Worklist</label>
<input type="text" id="created_on_work_list" class="form-control" placeholder="Created On Worklist" value="<?= $row['Created_On_Worklist']; ?>" name="createdonworklist">
</div>
<div class="col-sm-4">
<label>Created Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="created_date" class="form-control" placeholder="Created Date" value="<?= $row['Create_Date']; ?>" name="createdate">
</div>
</div>
<div class="col-sm-4">
<label>Created time</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="time" id="created_time" class="form-control" placeholder="Created Time" value="<?= $row['Create_Time']; ?>" name="createtime">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Days Old</label>
<input type="text" id="days_old" class="form-control" placeholder="Days old" value="<?= $row['Days_Old']; ?>" name="daysold">
</div>
<div class="col-sm-4">
<label>Check</label>
<input type="text" id="check" class="form-control" placeholder="Check" value="<?= $row['Check_Status']; ?>" name="checkstatus">
</div>
<div class="col-sm-4">
<label>Ticket Status</label>
<input type="text" id="ticket_status" class="form-control" placeholder="Ticket Status" value="<?= $row['Ticket_Status']; ?>" name="ticketstatus">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Interval</label>
<input type="text" id="interval" class="form-control" placeholder="Interval" value="<?= $row['Interval_Onlist']; ?>" name="intervalonlist">
</div>
<div class="col-sm-4">
<label>Related Status</label>
<input type="text" id="relate_status" class="form-control" placeholder="Relate Status" value="<?= $row['Relate_Status']; ?>" name="relatestatus">
</div>
<div class="col-sm-4">
<label>WFA TR Num</label>
<input type="text" id="wfa_tr_num" class="form-control" placeholder="WF TR Num" value="<?= $row['WFA_TR_Num']; ?>" name="wfatrnum">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Recent WFA Dispatch Status</label>
<input type="text" id="recent_wfa_dispatch_status" class="form-control" placeholder="Recent WFA Dispatch Status"
value="<?= $row['Recent_WFA_Dispatch_Status']; ?>" name="recentwfadispatchstatus">
</div>
<div class="col-sm-4">
<label>Entity Status</label>
<input type="text" id="entity_status" class="form-control" placeholder="Intity Status" value="<?= $row['Entity_Status']; ?>" name="entitystatus">
</div>
<div class="col-sm-4">
<label>Entity</label>
<input type="text" name="entity" id="entity" class="form-control" placeholder="Entity" value="<?= $row['Entity']; ?>" name="entity">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Last Owner</label>
<input type="text" id="last_owner" class="form-control" placeholder="Last Owner" value="<?= $row['Last_Owner']; ?>" name="lastowner">
</div>
<div class="col-sm-4">
<label>First Cond Type</label>
<input type="text" id="first_cond_type" class="form-control" placeholder="First Cond Type" value="<?= $row['First_Cond_Type']; ?>" name="firstcondtype">
</div>
<div class="col-sm-4">
<label>Last Cond Type</label>
<input type="text" id="last_cond_type" class="form-control" placeholder="Last Cond Type" value="<?= $row['Last_Cond_Type']; ?>" name="lastcondtype">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>State</label>
<input type="text" id="state" class="form-control" placeholder="State" value="<?= $row['State']; ?>" name="st">
</div>
<div class="col-sm-4">
<label>Check Active</label>
<input type="text" id="check_active" class="form-control" placeholder="Check Active" value="<?= $row['Check_Active']; ?>" name="checkactive">
</div>
<div class="col-sm-4">
<label>Check Jepd</label>
<input type="text" name="check_jepd" id="check_jepd" class="form-control"placeholder="Check Jepd" value="<?= $row['Check_Jepd']; ?>" name="checkjepd">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>CLLI</label>
<input type="text" id="clli" class="form-control" placeholder="CLLI" value="<?= $row['CLLI']; ?>" name="clli">
</div>
<div class="col-sm-4">
<label>Resolved Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="resolved_date" class="form-control" placeholder="Resolved_Date" value="<?= $row['Resolved_Date']; ?>" name="resolved_date">
</div>
</div>
<div class="col-sm-4">
<label>Filtered Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="filtered_date" class="form-control" placeholder="Filtered Date" value="<?= $row['Filtered_Date']; ?>" name="filtereddate">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<label>Filtered By</label>
<input type="text" id="filtered_by" class="form-control" placeholder="Filtered by" value="<?= $row['Filtered_By']; ?>" name="filteredby">
</div>
<div class="col-sm-4">
<label>Restored Date</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-calendar"></i>
</span>
<input type="date" id="restored_date" class="form-control" placeholder="Restored_Date" value="<?= $row['Restored_Date']; ?>" name="restoreddate">
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-4 ">
<label class="text-bold"> NMA Comments subform </label>
</div>
<div class="col-sm-4">
</div>
</div>
<hr>
<div class="form-group">
<?php
$io = mysqli_query($db,"select * from NMA_Comments where NMA_Tkt_Num='$row[NMA_Ticket_Number]'");
$tr=mysqli_fetch_assoc($io);
?>
<div class="col-sm-4">
<label>NMA Ticket Number</label>
<input type="text" name="NMA_Ticket_Number" id="nma_ticket_number" class="form-control" placeholder="NMA Ticket Number" value="<?php echo $tr['NMA_Tkt_Num']; ?>" >
</div>
<div class="col-sm-4">
<label>NMA Notes</label>
<textarea type="text" name="NMA_Notes" id="nma_notes" class="form-control" placeholder="NMA Notes"><?php echo $tr['NMA_Notes']; ?></textarea>
</div>
<div class="col-sm-4">
<label>NMA Note Date</label>
<input type="text" name="NMA_Ticket_Date" id="nma_ticket_number" class="form-control" placeholder="NMA Ticket Number" value="<?php echo $tr['NMA_Note_Date']; ?>">
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<button class="btn btn-primary" name="UPDATE_RAW"> Save and Close</button>
</div>
<div class="col-sm-4">
<button class="btn btn-success" name="MOVE_TO_RESOLVED"> Resolved and Close</button>
</div>
<div class="col-sm-4">
<button class="btn btn-danger" name="MOVE_TO_INHIBITS"> Inhibit and Close</button>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
<?php
if(isset($_POST['UPDATE_RAW'])){
extract($_POST);
//print_r($_POST);
$sql=mysqli_query($db,"update nma_raw set NMA_System='$nmasystem',NMA_Ticket_Number='$nmaticketnum',Tkt_Priority='$tktpriority',Created_On_Worklist='$createdonworklist',Create_Date='$createdate',Create_Time='$createtime',Days_Old='$daysold',Interval_Onlist='$intervalonlist',Check_Status='$checkstatus',Ticket_Status='$ticketstatus',Relate_Status='$relatestatus',WFA_TR_Num='$wfatrnum',Recent_WFA_Dispatch_Status='$recentwfadispatchstatus',Last_Owner='$lastowner',Entity_Status='$entitystatus',Entity='$entity',First_Cond_Type='$firstcondtype',Last_Cond_Type='$lastcondtype',State='$st',CLLI='$clli',Check_Active='$checkactive',Check_Jepd='$checkjepd', Resolved_Date='$resolved_date' WHERE ID='$id'");
if($sql){
echo"<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else{
echo"<script>alert('Some ERRORS');</script>";
}
}
?>
<?php
if(isset($_POST['MOVE_TO_INHIBITS'])){
extract($_POST);
//$print_r($_POSt);
$sql=mysqli_query($db,"INSERT INTO nma_main_table SELECT * FROM nma_raw where ID='$id'");
if($sql){
echo"<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else{
echo"<script>alert('Some ERRORS');</script>";
}
// sql to delete a record
$sql=mysqli_query($db,"DELETE FROM nma_raw WHERE ID='$id'");
if ($sql){
echo "Record Inhibited successfully";
} else {
echo "<script>alert('Error in deletion');</script>";
}
}
?>
<?php
if(isset($_POST['MOVE_TO_RESOLVED'])){
extract($_POST);
//$print_r($_POSt);
$sql=mysqli_query($db,"INSERT INTO nma_main_table SELECT * FROM nma_raw where ID='$id'");
if($sql){
echo"<script>alert('Updated SuccessFully');window.location.href='Active_Tkt_Qry_List_Frm_NMA.php';</script>";
}
else{
echo"<script>alert('Some ERRORS');</script>";
}
// sql to delete a record
$sql=mysqli_query($db,"DELETE FROM nma_raw WHERE ID='$id'");
if ($sql){
echo "Record Resolved successfully";
} else {
echo "<script>alert('Error in deletion');</script>";
}
}
?>
<?php include_once "footer.php";?>
If the error you're getting is Incorrect date value: '' for column 15daytkt.nma_raw.Resolved_Date (as you've mentioned in the comments) :
It looks like you are passing an empty string to the Resolved_Date column, and it's invalid. Please make sure you're actually passing a valid date string in this format 2019-11-15. Usually, the HTML form inputs with the date type return this format.
You can verify this case by setting the value to NULL if it's empty. Try changing the query as below:
$sql = mysqli_query($db,"update nma_raw set NMA_System='$nmasystem', Resolved_Date=NULLIF($resolved_date, '') WHERE ID='$id'");
Note the NULLIF($resolved_date, '') part. It will basically set the value to null if it is empty.
Hope it helps.
If there are any errors while registration or login into the sit then it is not displaying the error message just printing the variable.Here is the code.Tried by doing echo as well but it is also not working.Tried with storing the result in a variable and displaying the message but still not worked.
<?php
include 'includes/db.php';
$match = '';
if(isset($_POST['submit_user']))
{
$email = $_POST['email'];
$check=mysqli_query($conn,"select * from users where user_email='$email'");
$checkrows=mysqli_num_rows($check);
if($checkrows>0)
{
$msg = "Email Already Exists";
header('Location:registration.php?msg=$msg');
}
else
{
if($_POST['password'] == $_POST['con_password'])
{
$ins_sql = "INSERT INTO users (first_name, last_name, user_email, user_password, username) VALUES ('$_POST[first_name]', '$_POST[last_name]', '$_POST[email]', '$_POST[password]', '$_POST[username]')";
$run_sql = mysqli_query($conn,$ins_sql);
}
else
{
$match = '<div class="alert alert-danger">Password doesn't match!</div>';
}
}
}
?>
<form class="form-horizontal" action="registration.php" method="post" role="form">
<div class="body">
<div class="row clearfix">
<div class="col-sm-6 col-xs-12">
<div class="form-group">
<div class="form-line">
<input type="text" class="form-control" placeholder="First Name" name="first_name" id="first_name" onkeypress="return checkSpcialChar(event)" required>
</div>
</div>
</div>
<div class="col-sm-6 col-xs-12">
<div class="form-group">
<div class="form-line">
<input type="text" class="form-control" placeholder="Last Name" name="last_name" id="last_name" required>
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-sm-12">
<div class="form-group">
<div class="form-line">
<input type="text" class="form-control" placeholder="Enter Your Email" name="email" id="email" required>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<div class="form-line">
<input type="password" class="form-control" placeholder="Password" name="password" id="password" required>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<div class="form-line">
<input type="type" class="form-control" placeholder="Confirm Password" name="con_password" id="con_password" required>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<div class="form-line">
<input type="text" class="form-control" placeholder="Enter Username" name="username" id="username">
</div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group drop-custum">
<select class="form-control show-tick" name="user_role" id="user_role" required>
<option value="">-- Select User role --</option>
<option value="admin">Admin</option>
<option value="employee">Employee</option>
</select>
</div>
</div>
<div class="col-sm-12">
<button type="submit" class="btn btn-raised g-bg-cyan" name="submit_user" id="subject">Submit</button>
<button type="submit" class="btn btn-raised">Cancel</button>
</div>
<span>
<?php if(isset($_GET['msg']))
echo $_GET['msg'];
?>
</span>
</div>
</div>
</form>
I have created a register form but whenever I try to insert data to database it dont give me error rather it stays on the same page with the filled data.I have created this in codeigniter.Below is my code.
Controller File: Home.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session','form_validation','email'));
$this->load->database();
$this->load->model('Sign');
}
public function index()
{
$this->load->view('home/index');
}
function signup()
{
$occu = $this->input->post('occupation');
$cf = $this->input->post('codefest');
$this->form_validation->set_rules('fname','Name','trim|required');
$this->form_validation->set_rules('mobile','Mobile No','trim|required');
$this->form_validation->set_rules('email','Email','trim|required|valid_email');
$this->form_validation->set_rules('password','Password','trim|required');
$this->form_validation->set_rules('cpass','Cofirm Password','trim|required|matches[password]');
$this->form_validation->set_rules('occupation','Occupation','trim|required|callback_select_validate');
$this->form_validation->set_rules('institute','Institute Name','trim|required');
$this->form_validation->set_rules('company','Company Name','trim|required');
$this->form_validation->set_rules('codefest','Codefest','trim|required|callback_select_codefest');
$this->form_validation->set_rules('address1','Address','trim|required');
$this->form_validation->set_rules('city','City','trim|required');
$this->form_validation->set_rules('pincode','Pincode','trim|required');
if ($this->form_validation->run() == FALSE)
{
// fails
$this->load->view('home/index');
}
else
{
//echo "inserted";
$data = array
('user_name' => $this->input->post('fname'),
'mobile_no' => $this->input->post('mobile'),
'user_email' => $this->input->post('email'),
'user_password' => $this->input->post('cpass'),
'occupation' => $this->input->post('occupation'),
'institute_name' => $this->input->post('institute'),
'company_name' => $this->input->post('company'),
'codefest_city' => $this->input->post('codefest'),
'address' => $this->input->post('address1'),
'city' => $this->input->post('city'),
'pincode' => $this->input->post('pincode'));
// insert form data into database
if ($this->Sign->insertUser($data))
{
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Your Message has been successfully received.We will back to you soon.</div>');
redirect('home/index');
}
else
{
// error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error. Please try again later!!!</div>');
redirect('home/index');
}
}
}
// Below function is called for validating select option field.
function select_validate($occu)
{
if($occu=="none"){
$this->form_validation->set_message('select_validate', 'Please Select Your Occupation.');
return false;
} else{
// User picked something.
return true;
}
}
function select_codefest($cf)
{
if($cf=="none"){
$this->form_validation->set_message('select_codefest', 'Please Select a Codefest.');
return false;
} else{
// User picked something.
return true;
}
}
}
/* End of file Home.php */
/* Location: .//C/Users/CYBERBUFF/AppData/Local/Temp/fz3temp-1/Home.php */
Model File: Sign.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Sign extends CI_Model {
public function __construct()
{
parent::__construct();
$this->load->database();
}
function insertUsers($data)
{
return $this->db->insert('signup',$data);
}
}
/* End of file Sign.php */
/* Location: .//C/Users/CYBERBUFF/AppData/Local/Temp/fz3temp-1/Sign.php */
View File : index.php
<div class="second-col col-md-6 col-sm-3">
<?php echo $this->session->flashdata('msg'); ?>
<div class="contact-area-left">
<h4>Sign Up</h4>
<?php echo form_open('home/signup', array('class' =>'comments-form contact-form'));?>
<div class="row" align="center">
<div class="form-group col-lg-10">
<input type="text" class="form-control" name="fname" placeholder="Full Name" value="<?php echo set_value('fname');?>">
<span class="text-danger"><?php echo form_error('fname'); ?></span>
</div>
<div class="form-group col-lg-10">
<input type="text" class="form-control" name="mobile" placeholder="Your Mobile No" value="<?php echo set_value('mobile');?>">
<span class="text-danger"><?php echo form_error('mobile'); ?></span>
</div>
<div class="form-group col-lg-10">
<input type="text" class="form-control" name="email" placeholder="Email Address" value="<?php echo set_value('email');?>">
<span class="text-danger"><?php echo form_error('email'); ?></span>
</div>
<div class="form-group col-lg-5">
<input type="password" class="form-control" name="password" placeholder="Password" value="<?php echo set_value('password');?>">
<span class="text-danger"><?php echo form_error('password'); ?></span>
</div>
<div class="form-group col-lg-5">
<input type="password" class="form-control" name="cpass" placeholder="Confirm Password" value="<?php echo set_value('cpass');?>">
<span class="text-danger"><?php echo form_error('cpass'); ?></span>
</div>
<div class="form-group col-lg-10">
<select class="form-control" name="occupation" id="occupation" onchange="CheckContact(this.value);" >
<option value="none" selected="selected">------------Select Occupation------------</option>
<option value="student">Student</option>
<option value="professional">Professional</option>
</select>
<span class="text-danger"><?php echo form_error('occupation'); ?></span>
</div>
<div class="form-group col-lg-10" id="student" style="display: none;">
<input type="text" class="form-control" name="institute" placeholder="Institute Name" value="<?php echo set_value('institute');?>">
<span class="text-danger"><?php echo form_error('institute'); ?></span>
</div>
<div class="form-group col-lg-10" id="professional" style="display: none;">
<input type="text" class="form-control" name="company" placeholder="Company Name" value="<?php echo set_value('company');?>">
<span class="text-danger"><?php echo form_error('company'); ?></span>
</div>
<div class="form-group col-lg-10">
<select class="form-control" name="codefest">
<option value="none" selected="selected">------------Select Codefest------------</option>
<option value="cf_ agartala">Codefest Agartala</option>
<option value="cf_bhubaneswar">Codefest Bhubaneswar</option>
<option value="cf_chennai">Codefest Chennai</option>
<option value="cf_guwahati">Codefest Guwahati</option>
<option value="cf_kolkata">Codefest Kolkata</option>
</select>
<span class="text-danger"><?php echo form_error('codefest'); ?></span>
</div>
<div class="form-group col-lg-10">
<input type="text" class="form-control" name="address1" placeholder="Address" value="<?php echo set_value('address1');?>">
<span class="text-danger"><?php echo form_error('address1'); ?></span>
</div>
<!--<div class="form-group col-lg-5">
<input type="text" class="form-control" name="address2" placeholder="Address Line 2 (optional)" value="<?php echo set_value('address2');?>">
<span class="text-danger"><?php echo form_error('address2'); ?></span>
</div>-->
<div class="form-group col-lg-5">
<input type="text" class="form-control" name="city" placeholder="City" value="<?php echo set_value('city');?>">
<span class="text-danger"><?php echo form_error('city'); ?></span>
</div>
<div class="form-group col-lg-5">
<input type="text" class="form-control" name="pincode" placeholder="PIN Code" value="<?php echo set_value('pincode');?>">
<span class="text-danger"><?php echo form_error('pincode'); ?></span>
</div>
</div>
<div class="row" align="center">
<button class="btn btn-primary btn-lg">Register</button>
<button type="reset" class="btn btn-default btn-lg">Reset</button>
</div>
<?php echo form_close(); ?>
</div>
These required fields are hidden in form so validation fails;
<div class="form-group col-lg-10" id="student" style="display: none;">
<input type="text" class="form-control" name="institute" placeholder="Institute Name" value="<?php echo set_value('institute');?>">
<span class="text-danger"><?php echo form_error('institute'); ?></span>
</div>
<div class="form-group col-lg-10" id="professional" style="display: none;">
<input type="text" class="form-control" name="company" placeholder="Company Name" value="<?php echo set_value('company');?>">
<span class="text-danger"><?php echo form_error('company'); ?></span>
</div>
but validations are in controller
$this->form_validation->set_rules('institute','Institute Name','trim|required');
$this->form_validation->set_rules('company','Company Name','trim|required');
remove the validation if not needed. :)
i have a form whch sends data to the databse, after data is sent successfully i want to show success msg, but i dont want it to stay rather to disappear after a short while.
$nameErr=$drug_idErr=$priceErr=$quantityErr=$dateErr=$dateInvalid="";
$drug_id=$name=$price=$quantity=$date="";
if(isset($_POST['submit'])){
$drug_id=mysql_real_escape_string(addslashes($_POST['drug_id']));
$name=mysql_real_escape_string(addslashes($_POST['name']));
$price=mysql_real_escape_string(addslashes($_POST['price']));
$quantity=mysql_real_escape_string(addslashes($_POST['quantity']));
$date=mysql_real_escape_string(addslashes($_POST['date']));
if(empty($drug_id)){
$drug_idErr="Required";
}
elseif(empty($name)){
$nameErr="Required";
}
elseif(empty($price)){
$priceErr="Required";
}
elseif(empty($quantity)){
$quantityErr="Required";
}
elseif(empty($date)){
$dateErr="Required";
}
elseif(!preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $date)){
$dateInvalid="Invalid date format";
}
else{
//send data to database here
$_SESSION['success']="Drug added successfully";
$drug_id=$name=$price=$quantity=$date="";
}
}
the following is my form
<div class="well">
<form id="register-form" class="form-horizontal" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<legend>Add new drug</legend>
<?php if(!empty($_SESSION['success'])){
echo '<div class="alert alert-success">'.$_SESSION['success'].'</div>'; unset($_SESSION['success']);} ?>
<div class="control-group">
<label class="control-label">ID</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-ban-circle"></i></span>
<input type="text" class="input-xlarge" id="drug_id" name="drug_id" placeholder="Drug ID"
value="<?php echo htmlspecialchars($drug_id); ?>">
</div>
<span class="error"><?php echo $drug_idErr;?></span>
</div>
</div>
<div class="control-group ">
<label class="control-label">Name</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-pills"></i></span>
<input type="text" class="input-xlarge" id="name" name="name" placeholder="Drug Name"
value="<?php echo htmlspecialchars($name)?>">
</div>
<span class="error"><?php echo $nameErr;?></span>
</div>
</div>
<div class="control-group">
<label class="control-label">Price</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-dollars"></i></span>
<input type="text" class="input-small" id="price" name="price" placeholder="Drug Price"
value="<?php echo htmlspecialchars($price); ?>">
</div>
<span class="error"><?php echo $priceErr; ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label">Quantity</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-ban-circle"></i></span>
<input type="text" id="quantity" class="input-mini" name="quantity" placeholder="Quantity"
value="<?php echo htmlspecialchars($quantity);?>">
</div>
<span class="error"><?php echo $quantityErr;?></span>
</div>
</div>
<div class="control-group">
<label class="control-label">Expire Date</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-time"></i></span>
<td><input type="text" name="date" id="date" class="span2" placeholder="Expire date"
value="<?php echo htmlspecialchars($date); ?>"/>
</div>
<span class="error"><?php echo $dateErr.$dateInvalid; ?></span>
</div>
</div>
<div class="control-group">
<label class="control-label"></label>
<div class="controls">
<button type="submit" class="btn btn-success" name="submit" >Add</button>
</div>
</div>
</form>
</div>
now i can just show the alert but i don knw how to make it disappear
Try this:
$('.alert').hide()
Or you could use fading:
$('.alert').fadeOut(300)
I have a "create user"form with reset and create button. This reset button is not working for some drop-downs in the form.
In addition, reset button is not clearing all the values in the form after validation. It only clears the values entered after validation.
Here is my code:
<div class="form-action clearfix">
<button type="button" onClick="clearForm()" > Reset </button>
<button class="button" type="button" id="button" onclick="doAjax('index.php/users/createUser', convertFormJson('#createUserForm'));">Create</button>
and
function clearForm() {
document.getElementById('createUserForm').reset();
}
Form:
<?php echo validation_errors(); ?>
<div class="container_12 clearfix leading" >
<div class="grid_12">
<!--<form class= "form has-validation">-->
<?php
$attributes = array('class' => 'form has-validation', 'id' => 'createUserForm');
echo form_open('/users/createUser', $attributes);
?>
<div class="clearfix">
<label for="form-name" class="form-label">First Name <em>*</em></label>
<div class="form-input">
<input type="text" id="form-name" name="firstname" required="required" placeholder="Enter the first name" value="<?php echo set_value('firstname'); ?>" />
</div>
</div>
<div class="clearfix">
<label for="form-name" class="form-label">Last Name <em>*</em></label>
<div class="form-input">
<input type="text" id="form-name" name="lastname" required="required" placeholder="Enter the last name" value="<?php echo set_value('lastname'); ?>"/>
</div>
</div>
<div class="clearfix">
<label for="form-email" class="form-label">Email <em>*</em></label>
<div class="form-input"><input type="email" id="form-email" name="email" required="required" placeholder="A valid email address" value="<?php echo set_value('email'); ?>"/></div>
</div>
<!--
<div class="clearfix">
<label for="form-birthday" class="form-label">Birthdate</label>
<div class="form-input"><input type="date" id="form-birthday" name="date" placeholder="mm/dd/yyyy" value="<?php //echo set_value('date'); ?>" class="date"/></div>
</div>
-->
<div class="clearfix">
<label for="form-username" class="form-label">Username <em>*</em></label>
<div class="form-input">
<?php echo form_error('username'); ?>
<input type="text" id="form-username" name="username" value="<?php echo set_value('username'); ?>" required="required" maxlength="30" placeholder="Alphanumeric (max 30 char.)" />
</div>
</div>
<div class="clearfix">
<label for="form-password" class="form-label">Password <em>*</em></label>
<div class="form-input">
<?php echo form_error('password'); ?>
<input type="password" id="form-password" name="password" value="<?php echo set_value('password'); ?>" maxlength="30" placeholder="Min 8 char. containing a capital, number and/or symbol" />
</div>
</div>
<div class="clearfix">
<label for="form-password-check" class="form-label">Password check <em>*</em></label>
<div class="form-input">
<?php echo form_error('passconf'); ?>
<input type="password" id="form-password-check" name="passconf" value="<?php echo set_value('passconf'); ?>" data-equals="password" maxlength="30" placeholder="Re-enter your password" />
</div>
</div>
<div class="clearfix">
<label for="form-group" class="form-label">Group <em>*</em></label>
<div class="form-input">
<?php
$groupsData[' '] = "--";
$groupJs = 'id="form-group"';
echo form_dropdown('groupId', $groupsData,' ',$groupJs);
?>
</div>
</div>
<div class="clearfix">
<label for="form-language" class="form-label" >Language <em>*</em></label>
<div class="form-input">
<select id="form-language" name="language">
<option value ="" > -- </option>
<option value ="1">English</option>
<option value ="2">French</option>
</select>
</div>
</div>
<div class="clearfix">
<label for="form-timezone" class="form-label" >Timezone <em>*</em></label>
<div class="form-input">
<?php echo timezone_menu('UM5', 'form-timezone'); ?>
</div>
</div>
Please help me out.