I'm new to Codeigniter and I'm having problem with image upload function.
Error says - You did not select a file to upload.
Can anyone check my code and tell me what to do?
THIS IS MY CONTROLLER
This is my Controller which processes data.
public function add_data() {
$this->load->view('admin/header.php');
$this->load->library('form_validation');
$this->form_validation->set_rules('name', 'name', 'required');
$this->form_validation->set_rules('price', 'price', 'required');
$this->load->helper(array('form', 'url'));
if ($this->form_validation->run() == TRUE)
{
$this->load->view('admin/add_view.php');
$config['upload_path'] = './files/';
$config['allowed_types'] = 'jpg';
$this->load->library('upload', $config);
$this->upload->do_upload('picture');
$this->upload->data();
$data = array(
'name' => $this->input->post('name'),
'info' => $this->input->post('info'),
'gorod' => $this->input->post('gorod'),
'price' => $this->input->post('price'),
'amount' => $this->input->post('amount'),
'age' => $this->input->post('age'),
'status' => $this->input->post('status'),
'minbal' => $this->input->post('minbal'),
'contacts' => $this->input->post('contacts'),
'email' => $this->input->post('email'),
'alias' => $this->input->post('alias'),
'filename' => $this->input->post('picture')
);
$this->Adminmodel->add_record($data);
}
else
{
$this->load->view('admin/formnotsuccess');
}
}
VIEW
<form method="post" action="add_data" role="form" style="padding: 30px">
<div class="row">
<div class="form-group col-md-6 ">
<label>Название университета</label></br>
<input type="text" name="name" class="form-control" size="20">
</div>
</div>
<div class="row">
<div class="form-group col-md-10">
<label>Информация об университете</label></br>
<textarea id="textarea" name="info"></textarea>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Город</label></br>
<select class="form-control" id="gorod" name="gorod">
<option value="Алматы">Алматы</option>
<option value="Астана">Астана</option>
</select>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Стоимость обучения</label>
<input type="text" name="price" class="form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Количество студентов</label>
<input type="text" name="amount" class="form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Возраст университета</label>
<input type="text" name="age" class="form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Статус университета</label></br>
<select class="form-control" id="status" name="status">
<option value="Государственный">Государственный</option>
<option value="Частный">Частный</option>
</select>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Минимальный балл для поступления</label>
<input type="text" name="minbal" class="form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Контактные данные</label>
<textarea id="textarea2" name="contacts"></textarea>
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>E-mail</label></br>
<input type="text" name="email" class="form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Alias</label></br>
<input type="text" name="alias" class="form-control">
</div>
</div>
<div class="row">
<div class="form-group col-md-6">
<label>Картинка заднего фона</label></br>
<input type="file" name="picture" class="form-control">
</div>
</div>
<button type="submit" class="btn btn-default">Submit</button>
You are missing
enctype="multipart/form-data" in form
Read php file upload
And Upload code should be like bellow. Its easy to track your errors
if(!$this->upload->do_upload()) # do_upload('picture');
{
echo $this->upload->display_errors();
}
else
{
$data = $this->upload->data();
print_r($data);
}
Related
Please am trying to update my product entry in the database but I get an undefined variable error on submit. The form is supposed to update my database entry but when I route to the update method without passing the product id, I get a missing parameter product error and when add itas is the code below, I get an undefined variable product error
This is my update function
public function update(Request $request, Product $product)
{
$my_array = [$request->file('primary_image'), $request->file('image_1'), $request->file('image_2')];
$insert_array = [];
foreach ($my_array as $item) {
$save_url = '';
if ($item) {
$image = $item;
$name_gen = md5(rand(1000, 10000)) .'.'. $image->getClientOriginalExtension();
Image::make($image)->resize(523,605)->save('upload/products/'.$name_gen);
$save_url = 'upload/products/'.$name_gen;
}
array_push($insert_array, $save_url);
}
$product = Product::find($product->id);
$product->update([
'name' => $request->name,
'category' => $request->category,
'price' => $request->price,
'description' => $request->description,
'status' => $request -> status,
'estimated_delivery_time' => $request->estimated_delivery_time,
'available_quantity' => $request->available_quantity,
'colors' => $request->colors,
'supplier_name' => $request->supplier_name,
'supplier_phone' => $request->supplier_phone,
'video_description' => $request->video_description,
'primary_image' => $insert_array[0],
'image_1' => $insert_array[1],
'image_2' => $insert_array[2],
]);
$notification = array(
'message' => 'Product created successfully',
'alert-type' => 'success'
);
return redirect()->back()->with($notification);
}
this is my blade component
<form method="POST" action="{{route('products.update', ['products' => $product->id])}}" enctype="multipart/form-data">
{{ method_field('PUT') }}
#csrf
<h4 class="card-title">Edit Product</h4><br><br>
<div class="row">
<div class="col">
<div class="row mbr-1">
<label for="example-text-input" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-6">
<input name="name" class="form-control" type="text" value=""
id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
<div class="col">
<div class="row mb-3">
<label for="example-text-input"
class="col-sm-2 col-form-label">Category</label>
<div class="col-sm-6">
<input name="category" class="form-control" type="text" value=""
id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Price</label>
<div class="col-sm-6">
<input name="price" class="form-control" type="number"
value="" id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Status</label>
<div class="col-sm-6">
<input name="status" class="form-control" type="text" value=""
id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
</div>
</div>
<div class="container">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Product
Description</label>
<div class="col-sm-8">
<textarea id="elm1" name="description" placeholder="Please enter a vivid description of the product"></textarea>
</div>
</div>
<!-- end row -->
</div>
<div class="container">
<div class="row">
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Tags</label>
<div class="col-sm-6">
<input name="tags" class="form-control" type="text" value=""
id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Estimated
Delivery
Time</label>
<div class="col-sm-6">
<input name="estimated_delivery_time" class="form-control" type="text"
value="" id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Available
Quantity</label>
<div class="col-sm-6">
<input name="available_quantity" class="form-control" type="text"
value="" id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Colors</label>
<div class="col-sm-6">
<input name="colors" class="form-control" type="text" value=""
id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Supplier's
Name</label>
<div class="col-sm-6">
<input name="supplier_name" class="form-control" type="text"
value="" id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Supplier's
Contact</label>
<div class="col-sm-6">
<input name="supplier_contact" class="form-control" type="text"
value="" id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Video Url /
Link</label>
<div class="col-sm-6">
<input name="video_description" class="form-control" type="text"
value="" id="example-text-input">
</div>
</div>
<!-- end row -->
</div>
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Primarry
Image</label>
<div class="col-sm-6">
<input name="primary_image" accept="image/*" class="form-control"
type="file" id="image">
</div>
</div>
<!-- end row -->
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label"> Primary Image
Preview</label>
<div class="col-sm-6">
<img id="showImage" class="" width="300px" src="{{ (!empty($product->image))? url($product->image):url('upload/no_image.jpg') }}" alt="Product image">
{{-- <img id="showImage" class="" width="300px"src="{{ !empty($product->image) ? url($product->image):url('upload/no_image.jpg') }}"alt="Hero image"> --}}
</div>
</div>
<!-- end row -->
</div>
<div class="col">
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Add Second Image
</label>
<div class="col-sm-6">
<input name="image_1" accept="image/*" class="form-control"
type="file" id="image" multiple="">
</div>
</div>
<!-- end row -->
<div class="row mb-3">
<label for="example-text-input" class="col-sm-2 col-form-label">Add Third Image
</label>
<div class="col-sm-6">
<input name="image_2" accept="image/*" class="form-control"
type="file" id="image" multiple="">
</div>
</div>
</div>
</div>
<input type="submit" class="btn btn-info waves-effect waves-light" value="Edit Product">
</form>
Please what am I doing wrong?
Thanks for taking the time to review my code
Some refinements to add:
You have product from route model binding at first no need to find it again here: $product = Product::find($product->id);
You are passing the products but your route needs product.
Instead of {{ method_field('PUT') }} use #method('PUT') in your form.
If you had validation you had the data after validation and this code
$product->update([ 'name' => $request->name, 'category' => $request->category, 'price' => $request->price, 'description' => $request->description, 'status' => $request -> status, 'estimated_delivery_time' => $request->estimated_delivery_time, 'available_quantity' => $request->available_quantity, 'colors' => $request->colors, 'supplier_name' => $request->supplier_name, 'supplier_phone' => $request->supplier_phone, 'video_description' => $request->video_description, 'primary_image' => $insert_array[0], 'image_1' => $insert_array[1], 'image_2' => $insert_array[2], ]);
would be transferred to
$validatedData = $request->validate([ .... ]); $product->update($validatedData + [ 'primary_image' => $insert_array[0], 'image_1' => $insert_array[1], 'image_2' => $insert_array[2], ]);
or even moving the validation to a separate form request class.
I created a modal using Bootstrap, to add a new row into table.
I don't know why and how doesn't work.
This is table_edit.blade.php MODAL:
<div id="formModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Adaugare Rolete</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<span id="form_result"></span>
<form method="post" id="sample_form" class="form-horizontal" action ="{{route('tabledit.store')}}">
#csrf
<div class="form-group">
<label class="control-label col-md-4" >ProdusID : </label>
<div class="col-md">
<input type="text" name="ProdusID" id="ProdusID" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4">Denumire : </label>
<div class="col-md">
<input type="text" name="Denumire" id="Denumire" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" >Cant1 : </label>
<div class="col-md">
<input type="text" name="Cant1" id="Cant1" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" >Cant2 : </label>
<div class="col-md">
<input type="text" name="Cant2" id="Cant2" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" >Cant3 : </label>
<div class="col-md">
<input type="text" name="Cant3" id="Cant3" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" >Cant4 : </label>
<div class="col-md">
<input type="text" name="Cant4" id="Cant4" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" >Data : </label>
<div class="col-md">
<input type="date" name="Data" id="Data" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" >Pret Intrare : </label>
<div class="col-md">
<input type="text" name="Pret_Intrare" id="Pret_Intrare" class="form-control" />
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4" >Pret Iesire : </label>
<div class="col-md">
<input type="text" name="Pret_Iesire" id="Pret_Iesire" class="form-control" />
</div>
</div>
<br />
<div class="form-group" align="center">
<input type="hidden" name="action" id="action" value="Add" />
<input type="hidden" name="hidden_id" id="hidden_id" />
<input type="submit" name="action_button" id="action_button" class="btn btn-warning" value="Add" />
</div>
</form>
</div>
</div>
</div>
</div>
Here we can see I do an easy html bootstrap, it's oke, it's work, but affter, maybe in Controller it's the problem.
This is Controller:
public function store(Request $request){
$rules = array(
'ProdusID' => 'required',
'Denumire' => 'required',
'Cant1' => 'required',
'Cant2' => 'required',
'Cant3' => 'required',
'Cant4' => 'required',
'Data' => 'required',
'Pret_Intrare' => 'required',
'Pret_Iesire' => 'required'
);
$error = Validator::make($request->all(), $rules);
if($error->fails()){
return response()->json(['errors' => $error->errors()->all()]);
}
$form_data = array(
'ProdusID' => $request->ProdusID,
'Denumire' => $request->Denumire,
'Cant1' => $request->Cant1,
'Cant2' => $request->Cant2,
'Cant3' => $request->Cant3,
'Cant4' => $request->Cant4,
'Data' => $request->Data,
'Pret_Intrare' => $request->Pret_Intrare,
'Pret_Iesire' => $request->Pret_Iesire
);
Rolete::create($form_data);
return response()->json(['succes' => 'Data Added successfully.']);
}
And web:
Route::post('tabledit/store', 'TableditControllerRolete#store')->name('tabledit.store');
This is an image with modal
(!) UPDATE: I don't have any error, but he doesn't adding into table.
your form don't have an action attribute. you should fix that line with this:
<form method="post" id="sample_form" class="form-horizontal" action ="{{route('tabledit.store'}}">
This is my view page code
i check codeigniter form validation in codeigniter it's copy and paste my controller but same error
<form action="<?php echo base_url(); ?>admin/user_setup/store" method="post" class="ml-4 mr-4 mt-2" enctype="multipart/form-data">
<div class="row">
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<input type="text" name="firstname" id="firstname" placeholder="নাম" class="form-control form__field" required>
<label for="firstname" class="form__label">নাম </label>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<input type="text" name="username" id="username" placeholder="ইউজার নাম" class="form-control form__field" required>
<label for="username" class="form__label">ইউজার নাম </label>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<input type="text" name="email" id="email" placeholder="ই-মেইল" class="form-control form__field" required>
<label for="email" class="form__label">ই-মেইল </label>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<select name="activated" id="activated" class="form-control form__field" >
<option value="1">Active</option>
<option value="0">Inactive</option>
</select>
<label for="activated" class="form__label">অ্যাক্টিভেটেড</label>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<input type="password" name="password" id="password" placeholder="পাসওয়ার্ড" class="form-control form__field" required>
<label for="password" class="form__label">পাসওয়ার্ড</label>
</div>
</div>
<div class="col-lg-3 col-md-6 col-sm-12">
<div class="form-group form__group">
<input type="password" name="confirm_password" id="confirm_password" placeholder="কন্ফার্ম পাসওয়ার্ড" class="form-control form__field" required>
<label for="confirm_password" class="form__label">কন্ফার্ম পাসওয়ার্ড</label>
</div>
</div>
<div class="col-lg-2 col-md-6 col-sm-12">
<div class="form-group form__group">
<label for="logo" class="form__label">ছবি </label>
<input type="file" name="logo" id="logo" placeholder="ছবি" class="form-control form__field" rows="2" cols="2" style="height: 38px;"></input>
</div>
</div>
<div class="col-lg-2 col-md-6 col-sm-12">
<div class="form-group form__group">
<select name="type" id="type" class="form-control form__field" >
<option value="2">এডিটর</option>
<option value="3">লাইসেন্স অফিসার</option>
</select>
<label for="type" class="form__label">ইউজার টাইপ</label>
</div>
</div>
<div class="col-lg-2 col-md-6 col-sm-12">
<div class="form-group">
<input type="submit" value="তৈরি করুন" class="form-control btn btn-sm btn-primary mt-fl">
</div>
</div>
</div>
</form>
this is my controller code
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|min_length[6]|max_length[100]|alpha_dash');
$this->form_validation->set_rules('firstname', 'First Name', 'trim|required|xss_clean|min_length[6]|max_length[100]|alpha_dash');
$this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean|valid_email');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|minlength[6]|max_length[50]|alpha_dash');
$this->form_validation->set_rules('confirm_password', 'Confirm Password', 'trim|required|xss_clean|matches[password]');
$data['errors'] = array();
echo $this->form_validation->set_value('username');
echo $this->input->post('username');
if ($this->form_validation->run()) {
$data['username'] = $this->form_validation->set_value('username');
$data['firstname'] = $this->form_validation->set_value('firstname');
$data['email'] = $this->form_validation->set_value('email');
$data['password'] = $this->form_validation->set_value('password');
$data['created'] = date('Y-m-d H:i:s');
$data['activated'] = $this->input->post('activated');
$data['type'] = $this->input->post('type');
$insert_id = $this->web_model->insert('users', $data);
var_dump("asduasiduiasdijasidij");
} else {
$errors = $this->tank_auth->get_error_message();
foreach ($errors as $k => $v) $data['errors'][$k] = $this->lang->line($v);
// $this->render_page('admin/setup/user_setup/create', $data);
echo $this->form_validation->run();
var_dump($data['errors']);
}
form validation don't return anything and $this->form_validation->set_value('any'); is always be empty
I load form_validation in controller __construct and also check load function inner but error is absolute
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
Check your PHPMyAdmin, I got the same problem last month, find xampp with build in PHP 5.6, link here https://sourceforge.net/projects/xampp/files/XAMPP%20Windows/5.6.40/ , delete or rename your old Windows(c:)/xammp/ and replace with PHP 5.6
I am having one form with text, select, file fields.
I am using Codeigniter Framework.
I want to upload the selected file in 'uploads' folder and insert all form data with uploaded file name.
My code is below.
Please help me to complete this.
View :
<?php echo form_open_multipart('assign/task_assign'); ?>
<fieldset>
<div class="row">
<div class="col-md-2">Title</div>
<div class="col-md-10">
<div class="form-group">
<input class="form-control" name="task_title" type="text" required="required">
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">Description</div>
<div class="col-md-10">
<div class="form-group">
<textarea class="form-control" cols="80" rows="7" name="task_description"></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">Priority</div>
<div class="col-md-10">
<div class="form-group">
<select class="form-control" name="task_priority" required>
<option value="" disabled="disabled" selected="selected">Priority
</option>
<option value="Low">Low</option>
<option value="Medium">Medium</option>
<option value="High">High</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">Start Date</div>
<div class="col-md-10">
<div class="form-group">
<input class="form-control" name="task_start" id="datepicker" type="text" required="required" autocomplete="off">
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">Due Date</div>
<div class="col-md-10">
<div class="form-group">
<input class="form-control" name="task_due" id="datepicker1" type="text" required="required" autocomplete="off">
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">Assign To</div>
<div class="col-md-10">
<div class="form-group">
<select class="form-control" name="task_to" value="" required>
<option value="" disabled="disabled" selected="selected">To
</option>
<?php foreach ($h->result() as $row) { ?>
<option value="<?php echo $row->name; ?>"><?php echo $row->name; ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">Attachments</div>
<div class="col-md-10">
<div class="form-group">
<input type="file" class="form-control" name="userfile">
</div>
</div>
</div>
<div class="row">
<div class="col-md-2">Additional Information</div>
<div class="col-md-10">
<div class="form-group">
<textarea class="form-control" cols="80" rows="6" name="task_info"></textarea>
</select>
</div>
</div>
</div>
<input class="btn btn-primary btn-block" type="submit" value="Assign" required="required" name="assign">
</fieldset>
<?php echo form_close(); ?>
Controller :
public function task_assign()
{
$name=$this->session->userdata('name');
date_default_timezone_set('Asia/Calcutta');
$config = array(
'upload_path' => "./uploads/",
'overwrite' => TRUE,
'max_size' => "2048000",
);
$this->load->library('upload', $config);
$this->upload->do_upload();
$data=array('upload_data' => $this->upload->data());
$task=array(
'title'=>$this->input->post('task_title'),
'description'=>$this->input->post('task_description'),
'priority'=>$this->input->post('task_priority'),
'status'=>'Ongoing',
'start_date'=>$this->input->post('task_start'),
'due_date'=>$this->input->post('task_due'),
'end_date'=>$this->input->post('task_due'),
'assigned_to'=>$this->input->post('task_to'),
'assigned_by'=> $name,
'time'=> date('d-m-Y H:i:s'),
'task_file' => $upload_data['file_name'],
'additional_info'=>$this->input->post('task_info')
);
print_r($task);
$assign=$this->assign_model->assign_task($task);
if($assign)
{
$this->session->set_flashdata('error_msg', 'Could not Assign task');
redirect('assign');
}
else
{
$this->session->set_flashdata('success_msg', 'Task Assigned to ' .$task['assigned_to']. ' Successfully...');
redirect('assign');
}
}
Model :
class Assign_model extends CI_model{
/* Loading Parent Construct */
function __construct()
{
parent::__construct();
}
/* Get User Data From User Table */
public function fetchtable()
{
$query = $this->db->get('user');
return $query;
}
/* Insert Task Into 'issues' Database */
public function assign_task($task)
{
$this->db->insert('issues', $task);
}
}
I think the file name should give in the controller to upload. But i dont about how add it.
Only the file upload and getting file name is problem here. Please help me to do this..
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.