form in codeigniter cannot submit in controller - php

i have a problem regarding with form submission in my code. I have a form that would let the user to input his/her whole information profile and also in my form, i got dynamic input type boxes. In short i have a very large form in my html with JavaScript dynamic input type.
Now my problem is, i am printing the data submitted in my form from view to controller and it doesn't print anything or when i press submit button, the page only refreshes not submitting to the controller.
Here is my full view code:
<form name="Register" class="m-t" role="form" action="<?php echo site_url("user_login/register_user/reg_new") ?>" method="post">
<div class="container">
<div class="picture-container">
<div class="picture">
<img src="https://lh3.googleusercontent.com/LfmMVU71g-HKXTCP_QWlDOemmWg4Dn1rJjxeEsZKMNaQprgunDTtEuzmcwUBgupKQVTuP0vczT9bH32ywaF7h68mF-osUSBAeM6MxyhvJhG6HKZMTYjgEv3WkWCfLB7czfODidNQPdja99HMb4qhCY1uFS8X0OQOVGeuhdHy8ln7eyr-6MnkCcy64wl6S_S6ep9j7aJIIopZ9wxk7Iqm-gFjmBtg6KJVkBD0IA6BnS-XlIVpbqL5LYi62elCrbDgiaD6Oe8uluucbYeL1i9kgr4c1b_NBSNe6zFwj7vrju4Zdbax-GPHmiuirf2h86eKdRl7A5h8PXGrCDNIYMID-J7_KuHKqaM-I7W5yI00QDpG9x5q5xOQMgCy1bbu3St1paqt9KHrvNS_SCx-QJgBTOIWW6T0DHVlvV_9YF5UZpN7aV5a79xvN1Gdrc7spvSs82v6gta8AJHCgzNSWQw5QUR8EN_-cTPF6S-vifLa2KtRdRAV7q-CQvhMrbBCaEYY73bQcPZFd9XE7HIbHXwXYA=s200-no" class="picture-src" id="wizardPicturePreview" title="">
<input type="file" name="employee-picture" id="wizard-picture" class="">
</div>
<h6 class="">Choose Picture</h6>
</div>
</div>
<div class="register-body">
<p>Personal Information</p>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="text" name="user_id" id="user_id" class="form-control input-sm" placeholder="User ID" required>
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="text" name="first_name" id="first_name" class="form-control input-sm" placeholder="First Name" style="text-transform: capitalize;" required>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="text" name="middle_name" id="middle_name" class="form-control input-sm" placeholder="Middle Name" style="text-transform: capitalize;" required>
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="text" name="last_name" id="last_name" class="form-control input-sm" placeholder="Last Name" style="text-transform: capitalize;" required>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="email" name="email" id="email" class="form-control input-sm" placeholder="Email Address" required>
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="text" name="contact_no" id="contact_no" class="form-control input-sm" placeholder="Contact Number" required>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="password" name="password" id="password" class="form-control input-sm" placeholder="Password" required>
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="password" name="password_confirmation" id="password_confirmation" class="form-control input-sm" placeholder="Confirm Password" required>
</div>
</div>
</div>
<label for="cvil_stat">Permanent address</label>
<div class="row">
<div class="col-sm-3 col-sm-3 col-md-3">
<label for="cvil_stat">Province</label>
<br>
<select class="form-group" name="province" id="province_id">
<option> ----- Select Option ----- </option>
<?php foreach($provinces as $province)
echo '<option value='.$province->province_id.'>'.$province->province_name.'</option>'?>
</select>
</div>
<div class="col-sm-3 col-sm-3 col-md-3">
<label for="gender">City</label>
<br>
<select class="form-group" name="city" id="city_id">
<option> ----- Select Option ----- </option>
</select>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<br>
<input type="text" name="street_name" id="street_name" class="form-control input-sm" placeholder="House no. / Street name" required>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="text" name="philhealth_no" id="philhealth_no" class="form-control input-sm" placeholder="Philhealth Number" style="text-transform: capitalize;" required>
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="text" name="pagibig_no" id="pagibig_no" class="form-control input-sm" placeholder="Pag-ibig Number" required>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="text" name="tin_no" id="tin_no" class="form-control input-sm" placeholder="TIN Number" style="text-transform: capitalize;" required>
</div>
</div>
<div class="col-sm-6 col-sm-6 col-md-6">
<input type="text" name="dependentnumber" id="dependentnumber" class="form-control input-sm" placeholder="Number of Dependent Child" style="text-transform: capitalize;" required>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="text" name="sss_no" id="sss_no" class="form-control input-sm" placeholder="SSS Number" required>
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="text" name="place_ofb" id="place_ofb" class="form-control input-sm" placeholder="Place of Birth" style="text-transform: capitalize;" required>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-sm-6 col-md-6">
<label for="gender">Birthday</label>
<br>
<select class="form-group" name="bday_month">
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
<select class="form-group" name="bday_day">
<?php for($i=1;$i<32;$i++) { ?>
<option><?php echo $i ?></option>
<?php } ?>
</select>
<select class="form-group" name="bday_year">
<?php $y = date('Y'); ?>
<?php for($j=0;$j<120;$j++) { ?>
<option><?php echo $y-$j ?></option>
<?php } ?>
</select>
</div>
<div class="col-sm-6 col-sm-6 col-md-6">
<label for="gender">Religion</label>
<br>
<select class="form-group" name="religion">
<option> ----- Select Option ----- </option>
<?php foreach($religions as $religion)
echo '<option value='.$religion->religion_id.'>'.$religion->religion_name.'</option>'?>
</select>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-sm-6 col-md-6">
<label for="cvil_stat">Civil Status</label>
<br>
<select class="form-group" name="civil_stat" id="civil_stat">
<option> ----- Select Option ----- </option>
<option value="Single">Single</option>
<option value="Married">Married</option>
<option value="Legally Separated">Legally Separated</option>
<option value="Widowed">Widowed</option>
</select>
</div>
<div class="col-sm-6 col-sm-6 col-md-6">
<label for="gender">Citizenship</label>
<br>
<select class="form-group" name="citizenship">
<option> ----- Select Option ----- </option>
<?php foreach($citizenships as $citizenship)
echo '<option value='.$citizenship->citizenship_id.'>'.$citizenship->citizenship_name.'</option>'?>
</select>
</div>
</div>
<p>Family Background</p>
<div class="row" id="field_div">
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="text" name="fathers_name" id="fathers_name" class="form-control input-sm" placeholder="Father's Name" style="text-transform: capitalize;" required>
</div>
</div>
<div class="col-xs-3 col-sm-3 col-md-3">
<div class="form-group">
<input type="text" name="fathers_occu" id="fathers_occu" class="form-control input-sm" placeholder="Occupation" style="text-transform: capitalize;" required>
</div>
</div>
<div class="col-xs-3 col-sm-3 col-md-3">
<div class="form-group">
<input type="text" name="fdate_birth" id="fdate_birth" class="form-control input-sm" placeholder="Date of birth" style="text-transform: capitalize;" required>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6">
<div class="form-group">
<input type="text" name="mothers_name" id="mothers_name" class="form-control input-sm" placeholder="Mother's Name" style="text-transform: capitalize;" required>
</div>
</div>
<div class="col-xs-3 col-sm-3 col-md-3">
<div class="form-group">
<input type="text" name="mothers_occu" id="mothers_occu" class="form-control input-sm" placeholder="Occupation" style="text-transform: capitalize;" required>
</div>
</div>
<div class="col-xs-3 col-sm-3 col-md-3">
<div class="form-group">
<input type="text" name="mdate_birth" id="mdate_birth" class="form-control input-sm" placeholder="Date of birth" style="text-transform: capitalize;" required>
</div>
</div>
</div>
<p>Educational Background</p>
<div class="control-btns">
<div class="row">
<div class="col-xs-3 col-sm-3 col-md-3">
<button class="btn btn-primary btn-sm" onclick="add_field_educ(event);">+</button>
<button class="btn btn-danger btn-sm" onclick="remove_field_educ(event);">-</button>
</div>
</div>
</div>
<div id="wrapper_educ">
<div id="educ_div">
</div>
</div>
<p>Work Experience</p>
<div class="control-btns">
<div class="row">
<div class="col-xs-3 col-sm-3 col-md-3">
<button class="btn btn-primary btn-sm" onclick="add_field_work(event);">+</button>
<button class="btn btn-danger btn-sm" onclick="remove_field_work(event);">-</button>
</div>
</div>
</div>
<div id="wrapper_work">
<div id="work_div">
</div>
</div>
<div class="register_footer">
<button type="submit" value="Register" class="btn btn-primary">Register</button>
<button class="btn btn-primary">Clear</button>
</div>
</div>
</div>
</form>
Here is my controller code that i want to print my submitted code:
public function reg_new() {
$this->form_validation->set_message('is_unique', 'The %s is already taken.');
$this->form_validation->set_error_delimiters('<div class="error"><li>','</li></div>');
if ($this->form_validation->run('reg_config') == FALSE) {
$this->index();
} else {
$register_data = array(
'User_Id' => $this->input->post('user_id'),
'First_Name' => $this->input->post('first_name'),
'Middle_Name' => $this->input->post('middle_name'),
'Last_Name' => $this->input->post('last_name'),
'Email' => $this->input->post('email'),
'Contact_no' => $this->input->post('contact_no'),
'Password' => $this->bcrypt->hash_password($this->input->post('password')),
'City_id' => $this->input->post('city'),
'Street' => $this->input->post('street_name'),
'Philhealth_num' => $this->input->post('philhealth_no'),
'Pagibig_num' => $this->input->post('pagibig_no'),
'Tin_num' => $this->input->post('tin_no'),
'Dependent_children' => $this->input->post('dependentnumber'),
'Sss_num' => $this->input->post('sss_no'),
'Place_of_birth' => $this->input->post('place_ofb'),
'Gender' => $this->input->post('gender'),
'Birthdate' => $this->input->post('bday_year') . "-" . date("m",strtotime($this->input->post('bday_month'))) . "-" . $this->input->post('bday_day'),
'Religion' => $this->input->post('religion'),
'Citizenship' => $this->input->post('citizenship'),
'Civil_status' => $this->input->post('civil_stat'),
'fathers_name' => $this->input->post('fathers_name'),
'fathers_occupation' => $this->input->post('fathers_occu'),
'father_bdate' => $this->input->post('fdate_birth'),
'mothers_name' => $this->input->post('mothers_name'),
'mothers_occupation' => $this->input->post('mothers_occu'),
'mother_bdate' => $this->input->post('mdate_birth'),
'User_Status' => $this->user_stat,
'Delete_Status' => 0,
'Position_Id' => 0,
);
if($this->input->post('civil_stat') == 'Married') {
$spouse_data = array (
'Spouse_name' => $this->input->post('spouse_name'),
'Spouse_occupation' => $this->input->post('spouse_occu'),
'Spouse_bdate' => $this->input->post('spouse_dateofb'),
);
}
foreach ($this->input->post('educ_opt') as $educ) {
$count_educ = $count_educ++;
}
print_r($register_data);
print_r($count_educ);
print_r($spouse_data);
}
}
please take a look with my code why i cant submit it from controller.
thanks.

Thanks guys.. i just figured it out, its because of my form validation that i thought it doesn't submit because it did not satisfy my form validation and for that i returned $this->index();

Related

Cannot insert when clicking a button in Mysql using PHP

I am a beginner in web development, I used have an html elements, like textbox and other type of elements, I want to use them as my object and when they have a value and click a button, it will save the value of all the elements in mysql.
I have a code like this, but it cannot be inserted and anything does not happen when clicking a button.
Please help.
PHP:
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'ytp');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if(!$db ) {
die('Could not connect: ' . mysqli_error());
}
$fname = "";
$mname = "";
$lname = "";
$funame = "";
$cnum = "";
$bday = "";
$age = "";
$add = "";
if (isset($_POST['submit'])){
$fname = $_POST['fName'];
$mname = $_POST['mName'];
$lname = $_POST['lName'];
$funame = $_POST['fuName'];
$cnum = $_POST['Cnumber'];
$bday = $_POST['bday'];
$age = $_POST['age'];
$add = $_POST["address"];
}
$sql = "INSERT INTO employee ".
"(fName,mName,lName,fuName,cNumber,bDay,Age,Address) ".
"VALUES ('$fname','$mname','$lname','$funame','$cnum','$bday','$age','$add' )";
if (! mysqli_query($db , $sql)){
echo 'Cannot Insert';
}
else{
echo 'Success';
}
?>
HTML:
<div class="content">
<div class="row">
<div class="col-md-10">
<div class="card">
<div class="card-header">
<h5 class="title">Add User Information</h5>
</div>
<div class="card-body">
<form method="POST" action="php_functions\saveEmployee.php" name="INSERT">
<div class="row">
<div class="col-md-5 pr-md-1">
<div class="form-group">
<label>Company (disabled)</label>
<input type="text" class="form-control" disabled="" placeholder="Company" value="Benchmark Valuer's Inc.">
</div>
</div>
<div class="col-md-3 px-md-1">
<div class="form-group">
<label>ID</label>
<input type="text" class="form-control" placeholder="User ID" value="" id="id" name ="id" disabled>
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" placeholder="s.sample#gmail.com" id="email" name ="email">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>First Name</label>
<input type="text" class="form-control" placeholder="First Name" id="fName" name ="fName">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Middle Name</label>
<input type="text" class="form-control" placeholder="Middle Name" id="mName" name ="mName">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Last Name</label>
<input type="text" class="form-control" placeholder="Last Name" id="lName" name ="lName">
</div>
</div>
<div class="col-md-4 pl-md-1" hidden>
<div class="form-group">
<label>Fullname</label>
<input type="text" class="form-control" placeholder="Full Name" id="fuName" name ="fuName">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>Contact Number</label>
<input type="tel" class="form-control" placeholder="Contact Number" id="Cnumber" name="Cnumber">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Age</label>
<input type="number" class="form-control" placeholder="Age" id="age" name="age">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Birthday</label>
<input type="date" class="form-control" placeholder="Birthday" id="bday" name="bday">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Address</label>
<input type="text" class="form-control" placeholder="Home Address" id="address" name ="address">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" placeholder="Username" id="uName">
</div>
</div>
<div class="col-md-4 px-md-1">
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" placeholder="Password" id="pWord">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>UserType</label>
<input type="number" class="form-control" placeholder="0" id="uType">
</div>
</div>
</div>
<div class="row" hidden>
<div class="col-md-12">
<div class="form-group">
<label>Image Path:</label>
<input type="text" class="form-control" placeholder="C:\\" id="imageURL">
</div>
</div>
</div>
</form>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-fill btn-primary" id="submit" name="submit">Save</button>
<button class="btn btn-fill btn-success" id="btnBrowse">Browse</button>
<button class="btn btn-fill btn-danger" id="btnCancel">Cancel</button>
</div>
</div>
</div>
</div>
</div>
Your HTML form is closing before submit button. You should close that after submit button and also need to manage hierarchy of opening form tag as below:
<form method="POST" action="php_functions\saveEmployee.php" name="INSERT">
<div class="card-body">
<div class="row">
<div class="col-md-5 pr-md-1">
<div class="form-group">
<label>Company (disabled)</label>
<input type="text" class="form-control" disabled="" placeholder="Company" value="Benchmark Valuer's Inc.">
</div>
</div>
<div class="col-md-3 px-md-1">
<div class="form-group">
<label>ID</label>
<input type="text" class="form-control" placeholder="User ID" value="" id="id" name ="id" disabled>
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" placeholder="s.sample#gmail.com" id="email" name ="email">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>First Name</label>
<input type="text" class="form-control" placeholder="First Name" id="fName" name ="fName">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Middle Name</label>
<input type="text" class="form-control" placeholder="Middle Name" id="mName" name ="mName">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Last Name</label>
<input type="text" class="form-control" placeholder="Last Name" id="lName" name ="lName">
</div>
</div>
<div class="col-md-4 pl-md-1" hidden>
<div class="form-group">
<label>Fullname</label>
<input type="text" class="form-control" placeholder="Full Name" id="fuName" name ="fuName">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>Contact Number</label>
<input type="tel" class="form-control" placeholder="Contact Number" id="Cnumber" name="Cnumber">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Age</label>
<input type="number" class="form-control" placeholder="Age" id="age" name="age">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>Birthday</label>
<input type="date" class="form-control" placeholder="Birthday" id="bday" name="bday">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label>Address</label>
<input type="text" class="form-control" placeholder="Home Address" id="address" name ="address">
</div>
</div>
</div>
<div class="row">
<div class="col-md-4 pr-md-1">
<div class="form-group">
<label>Username</label>
<input type="text" class="form-control" placeholder="Username" id="uName">
</div>
</div>
<div class="col-md-4 px-md-1">
<div class="form-group">
<label>Password</label>
<input type="password" class="form-control" placeholder="Password" id="pWord">
</div>
</div>
<div class="col-md-4 pl-md-1">
<div class="form-group">
<label>UserType</label>
<input type="number" class="form-control" placeholder="0" id="uType">
</div>
</div>
</div>
<div class="row" hidden>
<div class="col-md-12">
<div class="form-group">
<label>Image Path:</label>
<input type="text" class="form-control" placeholder="C:\\" id="imageURL">
</div>
</div>
</div>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-fill btn-primary" id="submit" name="submit">Save</button>
<button class="btn btn-fill btn-success" id="btnBrowse">Browse</button>
<button class="btn btn-fill btn-danger" id="btnCancel">Cancel</button>
</div>
</form>
Hope it helps you.
the form has been closed before the submit button.
the </form> tag should be placed after the <div class="card-footer">...</div>.
please try it. hope it will help.

Inserting Multiple rows in mysql using codeigniter : it inserts only one row and in that one row stores only one first character

I tried to insert multiple rows in sql . But it inserts only the last one row and in that one row only storing first character of each column. I prints the query by echo, it shows only one last row, but gives all characters of each column. one more thing is iam inserting values in two tables by clicking on submit button. can anyone help on this.
Here it is the view :
<form class="" method="POST" enctype="multipart/form-data" action="<?php echo base_url(); ?>dashboard/addnewjobmela" >
<input type="hidden" name="csrfmiddlewaretoken" value="LgVIVf7yFe5bL9k2Rcj9TGLLpgKJX1LkmfiiptEZnN95y9WqKXHk7V4vGixmo6Wd">
<input type="hidden" id="cperson_no" value="1">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Job Mela Title</label>
<input class="form-control" type="text" name="title" required="" id="title">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4">
<div class="form-group">
<label>Job Mela Date</label>
<input class="form-control" type="date" name="date" required="" id="date">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4">
<div class="form-group">
<label>Last Date To Register</label>
<input class="form-control" type="date" name="laastdatetoregister" required="" id="laastdatetoregister">
</div>
</div>
<div class="col-xs-12 col-sm-12 ">
<div class="form-group">
<label>Venue Details</label>
<textarea class="form-control" name="venuedetails" cols="40" rows="2" required="" id="venuedetails"></textarea>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Contact Person</label>
<input class="form-control" type="text" name="contactperson" required="" id="contactperson">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Contact Emailid</label>
<input class="form-control" type="text" name="emailid" required="" id="emailid">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Contact Number</label>
<input class="form-control" type="text" name="contactnumber" required="" id="contactnumber">
</div>
</div>
</div>
<div class="row-fluid" >
<div style="background-color:#d6e9c6 !important;padding:10px"><p class="text-success"><b>Participating Companies</b></p></div>
</div>
<div class="col-xs-12 right" style="margin-top:-40px;margin-bottom: 20px">
<button class="btn btn-success" type="button" onclick="addingcompanies()">Add More</button>
</div>
<div id="companies">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Company Name</label>
<input class="form-control" type="text" name="company" required="" id="company">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Job Title</label>
<input class="form-control" type="text" name="jobtitle" required="" id="jobtitle">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Required Qualification</label>
<?php
echo form_dropdown('qualification', $education,'' ,'required="" class="form-control"');
?>
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Specialization</label>
<input class="form-control" type="text" name="specialization" required="" id="specialization">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Sector</label>
<input class="form-control" type="text" name="sector" required="" id="sector">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-4">
<div class="form-group">
<label>Job Type</label>
<?php
echo form_dropdown('jobtype', $jobtype,'' ,'required="" class="form-control"');
?>
</div>
</div>
<!-- <div class="col-xs-12 col-sm-12 col-md-4">
<div class="form-group">
<label>Company Logo</label>
<input class="form-control" type="file" name="picture" accept=".jpeg,.JPEG,.JPG,.jpg,.png,.PNG" required="" id="id_picture">
</div>
</div> -->
<div class="col-xs-12 col-sm-12 col-md-4 ">
<div class="form-group">
<label>Job Location</label>
<input class="form-control" type="text" name="joblocation" required="" id="joblocation">
</div>
</div>
</div>
</div>
<div class="col-xs-12" style="text-align:center">
<button class="btn btn-success" type="submit" value="Save Profile">Submit</button>
</div>
</form>
Javascript/Jquery to add ADD More Fields
<script type="text/javascript">
function addingcompanies()
{
var cperson_no = $('#cperson_no').val();
var j=parseInt(cperson_no)+1;
$('#cperson_no').val(j);
var qualification = '<?php echo str_replace("'", '', preg_replace("/\r|\n/", "", form_dropdown('qualification', $education,'' ,'required="" class="form-control"'))); ?>';
var jobtype = '<?php echo str_replace("'", '', preg_replace("/\r|\n/", "", form_dropdown('jobtype', $jobtype,'' ,'required="" class="form-control"'))); ?>';
$('#companies').append('<div class="row group"><hr/><div class="col-xs-12 col-sm-12 col-md-4 "> <div class="form-group"> <label>Company Name</label> <input class="form-control" type="text" name="company" required="" id="company' + cperson_no + '"> </div></div><div class="col-xs-12 col-sm-12 col-md-4 "> <div class="form-group"> <label>Job Title</label> <input class="form-control" type="text" name="jobtitle" required="" id="jobtitle' + cperson_no + '"> </div></div><div class="col-xs-12 col-sm-12 col-md-4 "> <div class="form-group"> <label>Required Qualification</label> '+ qualification +'</div></div><div class="col-xs-12 col-sm-12 col-md-4 "> <div class="form-group"> <label>Specialization</label> <input class="form-control" type="text" name="specialization" required="" id="specialization' + cperson_no + '"> </div></div><div class="col-xs-12 col-sm-12 col-md-4 "> <div class="form-group"> <label>Sector</label> <input class="form-control" type="text" name="sector" required="" id="sector' + cperson_no + '"> </div></div><div class="col-xs-12 col-sm-12 col-md-4"> <div class="form-group"> <label>Job Type</label>'+jobtype+' </div></div><div class="col-xs-12 col-sm-12 col-md-4 "> <div class="form-group"> <label>Job Location</label> <input class="form-control" type="text" name="joblocation" required="" id="joblocation' + cperson_no + '"> </div></div><div class="col-xs-12 col-sm-4 col-md-4 "><button class="btn btn-danger" style="margin-top: 25px; !important;" type="button" onClick="con_grpremove(this)">Remove</button></div></div></div>');
}
function con_grpremove(obj) {
$(obj).closest(".group").remove();
}
</script>
Here it is the controller :
public function addnewjob()
{
$this->load->model('dashboard_model');
$result = $this->dashboard_model->addnewjob();
$this->session->msg = "New Job Added Successfully";
redirect('dashboard');
}
public function addnewjobmela()
{
$this->load->model('dashboard_model');
$result = $this->dashboard_model->addnewjobmela();
$this->session->msg = "New Job Mela Added Successfully";
redirect('dashboard');
}
Model :
public function addnewjobmela() {
$data['title'] = $this->input->post('title');
$data['date'] = $this->input->post('date');
$data['lastdate'] = $this->input->post('laastdatetoregister');
$data['venue'] = $this->input->post('venuedetails');
$data['contactperson'] = $this->input->post('contactperson');
$data['emailid'] = $this->input->post('emailid');
$data['contactnumber'] = $this->input->post('contactnumber');
$data['status'] = 1;
$data['id'] = $this->db->insert_id();
print_r($data);
$this->db->insert('jobmelas', $data);
$jobmelaid = $this->db->insert_id();
$jcdata['company'] = $this->input->post('company');
$jcdata['jobtitle'] = $this->input->post('jobtitle');
$jcdata['qualification'] = $this->input->post('qualification');
$jcdata['specialization'] = $this->input->post('specialization');
$jcdata['sector'] = $this->input->post('sector');
$jcdata['jobtype'] = $this->input->post('jobtype');
$this->insCompanies($jobmelaid, $jcdata);
}
public function insCompanies($jobmelaid, $jcdata, $update='') {
if($update == 'update'){
$this->db->query('delete from job_mela_companies where jobmelaid = '.$jobmelaid.'');
}
print_r($jcdata);
for ($i = 0; $i < count($jcdata['company']); $i++) {
$cp_data[] = array(
'jobmelaid' => $jobmelaid,
'company' => $jcdata['company'][$i],
'jobtitle' => $jcdata['jobtitle'][$i],
'qualification' => $jcdata['qualification'][$i],
'specialization' => $jcdata['specialization'][$i],
'jobtype' => $jcdata['jobtype'][$i],
'sector' => $jcdata['sector'][$i]
);
$this->db->insert('job_mela_companies', $cp_data);
}
}
First table is giving result correct but
The output of more fields giving like this:
try below array and remove $cp_data[] = array(....) from insCompanies function.
$cp_data = array(
'jobmelaid' => $jobmelaid,
'company' => $jcdata['company'][$i],
'jobtitle' => $jcdata['jobtitle'][$i],
'qualification' => $jcdata['qualification'][$i],
'specialization' => $jcdata['specialization'][$i],
'jobtype' => $jcdata['jobtype'][$i],
'sector' => $jcdata['sector'][$i]
);

laravel get parameter from url to pass it with the action of the form

so i have this problem that i can't get pass it, i'm trying to get an parameter i sent with this view
#if(Auth::user())
Apply
#else
Apply
#endif
when the user isn't login it redirect him to the register form and it send the 'VacanciesID' to the register form, so its there in the url but i can't get the parameter of the url to the blade to send it with the action of the form that looks like this /careers/1/apply i need '1'.
heres my register form
<form action="/register/" method="POST" class="careersform">
<input type="hidden" name="_token" id="csrf-token" value="{{ Session::token() }}" />
<h4>User Details</h4>
<hr>
<div class="row">
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>Username</label>
<input name="EmployeeUsername" type="text" class="form-control">
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>Password</label>
<input name="EmployeePassword" type="text" class="form-control">
</div>
</div>
</div>
<h4>Personal Details</h4>
<hr>
<div class="row">
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>First Name</label>
<input name="FName" type="text" class="form-control">
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>Last Name</label>
<input name="LName" type="text" class="form-control">
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>Gender</label>
<select name="Gender" class="form-control">
<option>Male</option>
<option>Female</option>
</select>
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>Date of Birth</label>
<input name="DOB" type="date" class="form-control">
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>Marital Status</label>
<select name="MaritalStatus" class="form-control">
<option>Single</option>
<option>Married</option>
<option>Other</option>
</select>
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>Country of Nationality</label>
<select name="CountryOfNationality" class="form-control">
<option>Jordan</option>
<option>Other..</option>
</select>
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>National ID</label>
<input name="NationID" type="text" class="form-control">
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>Image</label>
<input name="Image" type="file" class="form-control">
</div>
</div>
<div class="form-group col-md-6 col-xs-12">
<img id="ImgUpload" src="/images/avatar.png" alt="Uploaded Image"/>
</div>
</div>
<h4>Education Details</h4>
<hr>
<div class="row">
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>School's Name</label>
<input name="SchoolName" type="text" class="form-control">
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>Education Level</label>
<select name='EducationLevel' class="form-control">
<option>High school</option>
<option>Some college</option>
<option>Bachelor's degree</option>
<option>Master's degree</option>
</select>
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>Major</label>
<input name="EducationMajor" type="text" class="form-control">
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>GPA</label>
<input name="GBA" type="text" class="form-control">
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>Add Another Education</label>
<input name="education" type="text" class="form-control">
</div>
</div>
</div>
<h4>Experience Details</h4>
<hr>
<div class="row">
<div class="col-xs-12">
<div class="form-group careersform-group-styled required">
<label>Company's Name</label>
<input name="CompanyName" type="text" class="form-control">
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>Job Title</label>
<input name="JobTitle" type="text" class="form-control">
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>Salary</label>
<input name="Salary" type="text" class="form-control">
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>Start date</label>
<input name="StartDate" type="text" class="form-control">
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>End date</label>
<input name="EndDate" type="text" class="form-control">
</div>
</div>
<div class="col-md-6 col-xs-12">
<div class="form-group careersform-group-styled required">
<label>Add Another Experience</label>
<input name="anotherexperience" type="text" class="form-control">
</div>
</div>
</div>
<button type="submit" class="btn turquoiseButton">Submit</button>
</form>
register route:
Route::post('register/', 'UsersController#careerportalregister');
controller:
public function careerportalregister(request $request){
$EmployeeUsername = $request->input('username');
$EmployeePassword = $request->input('password');
$role_id = $request->input('role_id');
$rol = $request->input('roles');
$roles= explode("," ,$rol);
$validator = Validator::make($request->all(), [
'password' => 'required|min:5|confirmed',
'confirm_password' => 'required|min:6|confirmed'
]);
// if ($validator->fails()) {
// return redirect('/user/create')
// ->withErrors($validator)
// ->withInput();
// } else {
$employee = user::create([
'username' => $request->input('EmployeeUsername'),
'password' => bcrypt($request->input('EmployeePassword')),
]);
$Title = $request->input('Title');
$Gender = $request->input('Gender');
$FName = $request->input('FName');
$LName = $request->input('LName');
$DOB = $request->input('DOB');
$MaritalStatus = $request->input('MaritalStatus');
$CountryOfBirth = $request->input('CountryOfBirth');
$CountryOfNationality = $request->input('CountryOfNationality');
$NationID = $request->input('NationID');
$Image = $request->input('Image');
$user_id = $employee->id;
PersonalDetails::CreatePersonalDetails($Title,$Gender ,$FName ,$LName,$DOB,$MaritalStatus,$CountryOfBirth,$CountryOfNationality,$NationID,$Image,$user_id);
$EducationMajor = $request->input('EducationMajor');
$EducationLevel = $request->input('EducationLevel');
$SchoolName = $request->input('SchoolName');
$GBA = $request->input('GBA');;
$user_id = $employee->id;
EducationDetails::CreateEducationDetails($EducationMajor,$EducationLevel ,$SchoolName ,$GBA,$user_id);
$CompanyName = $request->input('CompanyName');
$StartDate = $request->input('StartDate');
$EndDate = $request->input('EndDate');
$Salary = $request->input('Salary');
$JobTitle = $request->input('JobTitle');
$UserID = $employee->id;
ExperienceDetails::CreateExperienceDetails($CompanyName,$StartDate ,$EndDate ,$Salary,$JobTitle,$UserID);
foreach ($roles as $role) {
$count = DB::table('roles')->where('name', $role)->count();
if ($count != 0) {
$s = DB::table('roles')->where('name', $role)->first();
DB::table('role_user')->insert([
'user_id' => $employee->id,
'role_id' => $s->id
]);
}
}
Auth::login($employee, $remember = true);
return Redirect::to('/apply/success/');
}
In controller \Request::segment(2)
In blade {{Request::segment(2)}}
2 is the index number, feel free to change it based on your needs.
I would pass the id to the register url as an optional parameter.
Like this :
Route::post('register/{vacanciesId?}', 'UsersController#careerportalregister');
Then get it in the controller and do what you want with it.
You could also save it in session.
Have a nice day,
Assuming this is on your vacancies page and the problem you are having is that you are not able to put the ID into the url you need to iterate through each vacancy and set the ID that way so that the links are generated with a unique ID for each vacancy.
Also considering you have two different ways to provide details for the vacancy you would need to to create two Route::Get' for /apply/success/{{id}} and /careers/{{id}}/apply
When displaying the vacancies, I assume you are retrieving from the datebase and iterating through the results to show in the view? You should edit your post and display that.

Laravel : How to make a page submit to itself

I'm working on a page for editing user profiles but I want the page am working on to submit to itself when it is submitted and show a message that the profile has been edited successfully. Please how do I do this ?
Here is what am working ?
<div class="row">
<div class="text-center title">Pricing</div>
<div class="text-center desc col-md-8 col-md-push-2">
{{$sitename}}
</div>
<div class="container" style="padding-top: 60px;">
<h1 class="page-header">Edit Profile</h1>
<div class="row">
<!-- left column -->
<form class="form-horizontal" role="form" method="post" action="/profile">
<div class="col-md-4 col-sm-6 col-xs-12">
<div class="text-center">
<img id="ShowImage" src="#"/>
<img src="http://localhost:8234/img/index.png" class="avatar img-circle img-thumbnail" alt="avatar" width="200" height="200">
<h6>Upload a different photo...</h6>
<input type="file" class="text-center center-block well well-sm" name="avatar_path" id="avatar_path" onchange="readURL(this);">
</div>
</div>
<!-- edit form column -->
<div class="col-md-8 col-sm-6 col-xs-12 personal-info">
<div class="alert alert-info alert-dismissable">
<a class="panel-close close" data-dismiss="alert">×</a>
<i class="fa fa-coffee"></i>
This is the <strong>Profile Page</strong>. Use this to <strong>ONLY</strong> change your peronsal details
</div>
<h3>Personal info</h3>
<input class="form-control" value="{{$userInfo['data']['id']}}" type="hidden" name="user_id">
<div class="form-group">
<label class="col-lg-3 control-label">First Name:</label>
<div class="col-lg-8">
<input class="form-control" value="{{$userInfo['data']['first_name']}}" type="text" name="first_name">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Last Name:</label>
<div class="col-lg-8">
<input class="form-control" value="{{$userInfo['data']['last_name']}}" type="text" name="last_name">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Username:</label>
<div class="col-lg-8">
<input class="form-control" value="{{$userInfo['data']['profile']['username']}}" type="text" name="username">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Email Address:</label>
<div class="col-lg-8">
<input class="form-control" value="{{$userInfo['data']['email']}}" type="text" name="email">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Gender</label>
<div class="col-lg-8">
<div class="ui-select">
<select id="gender" class="form-control" name="gender">
<option value="{{$userInfo['data']['profile']['gender']}}" selected>{{$userInfo['data']['profile']['gender']}}</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
<option value="Other">Other</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">City:</label>
<div class="col-lg-8">
<input class="form-control" value="{{$userInfo['data']['profile']['city']}}" type="text" name="city">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">State:</label>
<div class="col-lg-8">
<input class="form-control" value="{{$userInfo['data']['profile']['state']}}" type="text" name="state">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Country:</label>
<div class="col-lg-8">
<input class="form-control" value="{{$userInfo['data']['profile']['country']}}" type="text" name="country">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Mobile:</label>
<div class="col-lg-8">
<input class="form-control" value="{{$userInfo['data']['profile']['mobile']}}" type="text" name="mobile">
</div>
</div>
<div class="form-group">
<label class="col-lg-3 control-label">Occupation:</label>
<div class="col-lg-8">
<input class="form-control" value="{{$userInfo['data']['profile']['occupation']}}" type="text" name="occupation">
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<input class="bkgrnd-blue text-white btn btn-primary" value="Update Profile" type="submit">
<span></span>
Cancel
</div>
</div>
</form>
</div>
</div>
</div>
This solution came from https://laravel.io/forum/01-30-2015-form-submission-to-the-same-page. Hope it helps
I have done a get route to display the page. I then did route a post to post form data.
Then I passed the $data variable to blade where I did an isset to check if it is created which displays the results
Display initial page
public function destinationSearchGet(){
$headData = array('pageTitle' => 'Admin Home - View all destinations');
return view('admin.destination_search', $headData);
}
post data back to the same page and create a new variable
public function destinationSearchPost(){
$headData = array('pageTitle' => 'Admin Home - Search results');
$formData = Request::input('destination');
$data = ParentRegionList::destinationSearch($formData);
return view('admin.destination_search', $headData)->with(compact('data'))
}
use blade to check if it exists
#if (isset($data))
<p>{{dd($data)}}</p>
#endif

can't tap on a php included section on mobile

I have an HTML page where a form section is included like this :
<?php include 'templates/register-form.php'?>
In a web browser there is no problem and everythig is working .
But on mobile , i can see the section , but cannot tap on it , the input doesn't react and neither the buttons .
What can it be?
thanx!
the code below is the included section.
<form role="form">
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 pull-right">
<div class="form-group">
<label for="nusername" language="en">username :</label>
<input type="text" class="form-control input-sm login-input" name="nusername" placeholder="שם משתמש" value="<?php echo Input::get('username')?>">
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 pull-right">
<div class="form-group">
<label for="fullname" language="en">full name :</label>
<input type="text" class="form-control input-sm login-input" name="fullname" placeholder="שם מלא" value="<?php echo Input::get('fullname')?>">
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 pull-right">
<div class="form-group">
<label for="npassword" language="en">password :</label>
<input type="password" class="form-control input-sm login-input" name="npassword" placeholder="שם מלא" value="<?php echo Input::get('password')?>">
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 pull-right">
<div class="form-group">
<label for="password_again" language="en">password again :</label>
<input type="password" class="form-control input-sm login-input" name="password_again" placeholder="הקלד את הסיסמא שנית" value="<?php echo Input::get('password_again')?>">
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 pull-right">
<div class="form-group">
<label for="email" language="en">email:</label>
<input type="email" class="form-control input-sm login-input" name="email" placeholder="אי-מייל" value="<?php echo Input::get('email')?>">
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 pull-right">
<div class="form-group">
<label for="adress" language="en">adress:</label>
<input type="text" class="form-control input-sm login-input" name="adress" placeholder="כתובת" value="<?php echo Input::get('adress')?>">
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 pull-right">
<div class="form-group">
<label for="phone" language="en">phone:</label>
<input type="tel" class="form-control input-sm login-input" name="phone" placeholder="טלפון" value="<?php echo Input::get('phone')?>">
</div>
</div>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 pull-right">
<div class="form-group">
<a class="form-control input-sm register-button btn btn-success pull-left" name="register-button" >הירשם</a>
</div>
</div>
In each field, your label attaches to the input field using the for-attribute. Safari connects for-attributes to id's, not names. Add the correct id to each of your inputs.
Example:
<div class="col-lg-4 col-md-4 col-sm-12 col-xs-12 pull-right">
<div class="form-group">
<label for="nusername" language="en">username :</label>
<input type="text" class="form-control input-sm login-input" id="username" name="nusername" placeholder="שם משתמש" value="<?php echo Input::get('username')?>">
</div>
</div>
Also, I suspect you just left it out of your example, but don't forget your tag, which might cause some issues in the Browser.

Categories