Codeigniter Cannot submit an ip adres on a form. Throws a Forbidden error - forms

Here is my html form.
<?php echo form_open(base_url('admin/subeler/add'), 'class="form-horizontal"'); ?>
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="grup">Grup Adı</label>
</div>
<div class="col-lg-8 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="text" id="grup" required name="grup" value="<?php echo set_value('grup'); ?>" class="form-control">
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="name">Şube Adı</label>
</div>
<div class="col-lg-8 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="text" id="name" required name="name" value="<?php echo set_value('name'); ?>"class="form-control">
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="ip">İp Adresi</label>
</div>
<div class="col-lg-8 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="text" id="ip" required name="ip" value="<?php echo set_value("ip"); ?>"class="form-control">
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="path">Database Adı</label>
</div>
<div class="col-lg-8 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="text" id="path" required name="path" value="<?php echo set_value('path'); ?>"class="form-control">
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="lisans">Lisans Tarihi</label>
</div>
<div class="col-lg-8 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="text" id="lisans" required name="lisans" value="<?php echo set_value('lisans'); ?>"class="form-control">
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="il">İl</label>
</div>
<div class="col-lg-8 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="text" id="il" name="il" value="<?php echo set_value('il'); ?>"class="form-control">
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label">
<label for="ilce">İlçe</label>
</div>
<div class="col-lg-8 col-md-10 col-sm-8 col-xs-7">
<div class="form-group">
<div class="form-line">
<input type="text" id="ilce" name="ilce" value="<?php echo set_value('ilce'); ?>"class="form-control">
</div>
</div>
</div>
</div>
<div class="row clearfix">
<div class="col-lg-offset-2 col-md-offset-2 col-sm-offset-4 col-xs-offset-5">
<input type="submit" name="submit" value="EKLE" class="btn btn-success m-t-15 waves-effect">
</div>
</div>
<?php echo form_close();?>
When I enter an ip adres to the input field like (http://xxx.xxx.xx.xx:xx/) redirect me to the 403 Forbidden page but when I put " (like "http://xxx.xxx.xx.xx:xx") to the ip adres it work fine. I tried to disable xss-filter disable in config files but result is same. Can anyone give some advice. How to submit an ip adres correctly with Codeigniter?
Server-Side
public function add()
{
if ($this->input->post("submit")) {
$this->form_validation->set_rules('grup', 'Grup Adı', 'trim|required');
$this->form_validation->set_rules('name', 'Şube Adı', 'trim|required');
$this->form_validation->set_rules('ip', 'İp Adresi', 'trim|required');
$this->form_validation->set_rules('path', 'Database Yolu', 'trim|required');
$this->form_validation->set_rules('lisans', 'Lisans Tarihi', 'trim|required');
if ($this->form_validation->run() == true) {
$data = array(
'name' => $this->input->post('name'),
'marka' => $this->input->post('grup'),
'ip' => $this->input->post('ip'),
'il' => $this->input->post('il'),
'ilce' => $this->input->post('ilce'),
'databasePath' => $this->input->post('path'),
'lisanse_date'=>$this->input->post('lisans')
);
$data = $this->security->xss_clean($data);
$result = $this->sube_model->add_sube($data);
if ($result) {
$this->session->set_flashdata('msg', 'Şube başarılı bir şekilde eklendi!');
redirect(base_url('admin/subeler'));
}
} else {
$data['view'] = 'admin/subeler/sube_ekle';
$this->load->view('layout', $data);
}
} else {
$data['view'] = 'admin/subeler/sube_ekle';
$this->load->view('layout', $data);
}
}

Unfortunately I could not test the code exactly as provided as I don't make use of CodeIgniter 3 anymore, so I translated it into CodeIgniter 4.
Also, I could not test what $this->sube_model->add_sube does.
This, plus the form view you provided is working when setting http://xx.xx.xx.xx:xx on every form field.
You should trace when the 403 forbidden is triggered.
If you make use of XDebug i'd recommend you to trace step by step where the execution fails.
Otherwise I'd just start removing code to find out at which point of the execution the exception is occurring.
If you are making use of a shared hosting, there could be any rule in the http server that is blocking the request, if that's the case, run it locally using a WAMP/LAMP bundle.
// CodeIgniter 4 approach
public function add() {
if ($this->request->getMethod() == 'post') {
$validation = \Config\Services::validation();
$validation->setRule('grup', 'Grup Adı', 'trim|required');
$validation->setRule('name', 'Şube Adı', 'trim|required');
$validation->setRule('ip', 'İp Adresi', 'trim|required');
$validation->setRule('path', 'Database Yolu', 'trim|required');
$validation->setRule('lisans', 'Lisans Tarihi', 'trim|required');
if ($validation->withRequest($this->request)->run() == true) {
$data = array(
'name' => $this->request->getPost('name'),
'marka' => $this->request->getPost('grup'),
'ip' => $this->request->getPost('ip'),
'il' => $this->request->getPost('il'),
'ilce' => $this->request->getPost('ilce'),
'databasePath' => $this->request->getPost('path'),
'lisanse_date'=>$this->request->getPost('lisans')
);
// $data = $this->security->xss_clean($data);
$result = $this->sube_model->add_sube($data);
$result = 1;
if ($result) {
session()->setFlashdata('msg', 'Şube başarılı bir şekilde eklendi!');
return redirect(base_url('admin/subeler'));
}
} else {
$data['view'] = 'admin/subeler/sube_ekle';
return view('layout', $data);
}
} else {
$data['view'] = 'admin/subeler/sube_ekle';
return view('layout', $data);
}
}

Related

update in codeigniter 3, it's run but database didnt changed

i dont understand with my code. it's run, and work. but when i see in database didnt changed.
here's my controller, function perbarui for get id data, get the data id from model (MMobil).
public function perbarui($id = NULL){
$this->load->model('merek');
$this->load->library('form_validation');
$data['merk'] = $this->merek->getList();
$data['detail'] = $this->MMobil->detail($id);
$submit = $this->input->post('submit');
print_r($data);
if ($submit) {
$nomor_kendaraan = $this->input->post('nomor_kendaraan');
$nomor_mesin = $this->input->post('nomor_mesin');
$id_merek = $this->input->post('id_merek');
$tahun_beli = $this->input->post('tahun_beli');
$nama_mobil = $this->input->post('nama_mobil');
$this->form_validation->set_rules('nama_mobil', 'Nama_Mobil', 'required');
$this->form_validation->set_rules('nomor_kendaraan', 'Nomor_Kendaraan', 'required');
$data['detik'] = $this->MMobil->setData($nomor_kendaraan, $nomor_mesin, $id_merek, $tahun_beli, $nama_mobil);
if ($this->form_validation->run() == FALSE) {
$data['errors'] = TRUE;
}else{
$data['detail'] = $this->MMobil->detail($id);
print_r($data);
}
//redirect('Master');
}
$this->load->view('master-detail-mobil', $data);
}
here's my models. function setData for storage variable after click submit. function edit get id data and get variable arrayData from function setData
public function setData($nomor_kendaraan, $nomor_mesin, $id_merek, $tahun_beli, $nama_mobil){
$this->nomor_kendaraan = $nomor_kendaraan;
$this->nomor_mesin = $nomor_mesin;
$this->id_merek = $id_merek;
$this->tahun_beli = $tahun_beli;
$this->nama_mobil = $nama_mobil;
}
public function edit($id){
$arrayData = array(
'nomor_kendaraan' => $this->nomor_kendaraan,
'nomor_mesin' => $this->nomor_mesin,
'id_merek' => $this->id_merek,
'tahun_beli' => $this->tahun_beli,
'nama_mobil' => $this->nama_mobil,
);
$this->db->where('nomor_mesin', $id);
return $this->db->update($this->table,$arrayData);
}
here's my views
<?php $this->load->view('header.php'); ?>
<?php
echo"<h4>UPDATE DATA</h4>";
?>
<form class="form-horizontal" role="form" method="post" action="<?php echo site_url()?>/Master/perbarui/">
<div class="form-group">
<label class="control-label col-sm-2" for="noken">Nomor Kendaraan :</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="nomor_kendaraan" value="<?php
echo #$detail->nomor_kendaraan;
?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="nomes">Nomor Mesin :</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="nomor_mesin" value="<?php
echo #$detail->nomor_mesin;
?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="merk">Merek Mobil :</label>
<div class="col-sm-10">
<select class="form-control" name="id_merek">
<?php foreach ($merk as $mrk) :?>
<option value="<?php echo $mrk->id_merek ?>">
<?php
echo $mrk->nama_merek;
?>
</option>
<?php endforeach?>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="thn">Tahun Beli :</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="tahun_beli" value="<?php
echo #$detail->tahun_beli; ?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="namo">Nama Mobil :</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="nama_mobil" value="<?php
echo #$detail->nama_mobil; ?>">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="nomes"></label>
<div class="col-sm-2">
<input type="submit" class="form-control" name="submit" value="simpan">
</div>
</div>
</form>
<?php $this->load->view('footer.php'); ?>
and here my pictures before click submit and after click submit. i typed print_r for see the data array. if you see data array detail before click submit, there is data in detail. but after click submit data array detail gone.
enter image description here enter image description here

Codeigniter 3 select form error not showing on form submit

I was following a youtube tutorial on making a codeigniter college management system
but i am stuck at a point.. when i try to submit the form on wamp server
select form fields not showing requied error on form submit
i have checked the name fields of the form inputs matching the database table but still when the form is submitted without any fiilling any fields
the role and gender select field errors doesnt show
here is my code
controller
welcome.php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* #see https://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
//$this->load->helper('url');
$this->load->view('home');
}
public function adminRegister()
{
$this->load->model('queries');
$roles = $this->queries->getRoles();
// print_r($roles);
// exit();
$this->load->view('register',['roles'=>$roles]);
}
public function adminLogin()
{
echo 'Login';
}
public function adminSignup()
{
//echo 'Registered succesfully';
$this->form_validation->set_rules('username','Username','required');
$this->form_validation->set_rules('email','Email','required');
$this->form_validation->set_rules('gender','Gender','required');
$this->form_validation->set_rules('role_id','Role','required');
$this->form_validation->set_rules('password','Password','required');
$this->form_validation->set_rules('confpwd','Password Again','required');
$this->form_validation->set_error_delimiters('<div class="text-danger">','</div>');
if($this->form_validation->run()){
echo 'validation passed';
}else{
//echo 'validation error';
echo validation_errors();
}
}
}
and views
register.php
<?php include('inc/header.php');?>
<div class="container mt-2">
<?php echo form_open('welcome/adminSignup',['class'=>'form-hoizontal']);?>
<h3 class="text-center display-4">ADMIN REGISTER</h3>
<hr/>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row">
<div class="col-md-3">
<label for="username" class="mt-2">User name:</label>
</div>
<div class="col-md-9">
<!-- <input type="text" class="form-control" placeholder="User name" id="username"> -->
<?php
$data = array(
'type' => 'text',
'name' => 'username',
'placeholder' => 'Enter Username',
'class' => 'form-control'
);
echo form_input($data); ?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('username','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="email" class="mt-2">Email address:</label>
</div>
<div class="col-md-9">
<!-- <input type="email" class="form-control" placeholder="Enter email" id="email"> -->
<?php
$data = array(
'type' => 'email',
'name' => 'email',
'placeholder' => 'Enter Email',
'class' => 'form-control'
);
echo form_input($data); ?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('email','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="gender" class="mt-2">Gender:</label>
</div>
<div class="col-md-9">
<!-- <input type="email" class="form-control" placeholder="Enter email" id="email"> -->
<select class="form-control" name="gender">
<option>Select</option>
<option>Male</option>
<option>Female</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('gender','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="email" class="mt-2">Role:</label>
</div>
<div class="col-md-9">
<select class="form-control" name="role_id">
<option>Select</option>
<?php if(count($roles)) { ?>
<?php foreach ($roles as $role){?>
<option><?php echo $role->rolename;?></option>
<?php }
} ?>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('role_id','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="password" class="mt-2">Password:</label>
</div>
<div class="col-md-9">
<!-- <input type="password" class="form-control" placeholder="Enter password" id="password"> -->
<?php
$data = array(
'type' => 'password',
'name' => 'password',
'placeholder' => 'Enter Password',
'class' => 'form-control'
);
echo form_input($data); ?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('password','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<div class="form-group">
<div class="row mt-3">
<div class="col-md-3">
<label for="password" class="mt-2">Password Again:</label>
</div>
<div class="col-md-9">
<!-- <input type="password" class="form-control" placeholder="Enter password" id="password"> -->
<?php
$data = array(
'type' => 'password',
'name' => 'confpwd',
'placeholder' => 'Enter Password Again',
'class' => 'form-control'
);
echo form_input($data); ?>
</div>
</div>
</div>
</div>
<div class="col-md-6">
<?php echo form_error('confpwd','<div class="text-danger">','</div>');?>
</div>
</div><!--row-->
<div class="row">
<div class="col-md-6">
<!-- <button type="submit" class="btn btn-dark float-right">Register</button> -->
<div class="float-right">
<?php echo form_submit('Register', 'Register',"class='btn btn-dark'"); ?>
<?php echo anchor('welcome','GO BACK',['class'=>'btn btn-warning']);?>
</div>
</div>
</div>
<?php echo form_close(); ?>
</div>
<?php include('inc/footer.php');?>
here is screenshot
The errors are not showing because your select boxes are always submitting a value. When you select an option in the selectbox and no value attribute is specified, the value after the <option> tag is being sent to the server.
To trigger the required rule, you need to send an empty string.
To do this, you can either use an empty <option> tag for the placeholder:
<select class="form-control" name="gender">
<option></option>
<option>Male</option>
<option>Female</option>
</select>
Or set the value attribute of the placeholder to an empty string:
<select class="form-control" name="gender">
<option value="">Select</option>
<option>Male</option>
<option>Female</option>
</select>
Try below Code:
<select class="form-control" name="gender">
<option></option>
<option value="male">Male</option>
<option valie="female">Female</option>
</select>

entire textbox isn't highlighted in asp.net mvc form

Login form
This is the code for the login form. From the picture it can be seen that the entire textbox isn't highlighted. What am I missing?
<div class="login">
<div class="login-form">
#using (Html.BeginForm("Login", "Account", FormMethod.Post, new { #class = "form-horizontal", role = "form" }))
{
#Html.AntiForgeryToken()
<h2 style="margin-left:-15px">Login</h2>
<div id="maintenance"></div>
<div class="bg-danger text-danger FailureCont">
</div>
<div class="form-group">
<span id="BodyContent_LoginCtrl_UserNameRequired" title="Username is required." class="bg-danger text-danger block" style="visibility:hidden">Username is required.</span>
<div class="input-group login-group">
<span class="input-group-addon">
<i class="fa fa-user"></i>
</span>
<div>#Html.TextBoxFor(m => m.UserName, new { #class = "form-control", placeholder = "Email", aria_required = true })</div>
#*#Html.ValidationMessageFor(m => m.UserName, "", new { #class = "text-danger" })*#
#* <input name="ctl00$BodyContent$LoginCtrl$UserName" type="text" id="BodyContent_LoginCtrl_UserName" tabindex="1" class="form-control" placeholder="Username" autocomplete="off" disabled="disabled" data-validate="placeholder required" />*#
</div>
</div>
<div class="form-group">
<span id="BodyContent_LoginCtrl_PasswordRequired" title="Password is required." class="bg-danger text-danger block" style="visibility:hidden;">Password is required.</span>
<div class="input-group login-group">
<span class="input-group-addon">
<i class="fa fa-lock"></i>
</span>
#*<input name="ctl00$BodyContent$LoginCtrl$Password" type="password" id="BodyContent_LoginCtrl_Password" tabindex="2" class="form-control" placeholder="Password" autocomplete="off" disabled="disabled" data-validate="placeholder required" />*#
#Html.PasswordFor(m => m.Password, new { #class = "form-control", placeholder = "Password" })
</div>
</div>
<div class="form-group">
<div class="col-sm-6 small-side-padding">
<button type="button" class="btn btn-secondary btn-block" id="" onclick="location.href='#Url.Action("Register","Account")'">Register</button>
</div>
<div class="col-sm-6 small-side-padding">
<input type="submit" class="btn btn-primary btn-block" id="bSummit" value="Login" />
#*<input type="submit" name="ctl00$BodyContent$LoginCtrl$LoadingLoginButton" value="Login" id="BodyContent_LoginCtrl_LoadingLoginButton" class="btn btn-primary btn-block hidden"/>*#
</div>
</div>
#*<input type="submit" name="ctl00$BodyContent$LoginCtrl$LoginButton" value="Login" class="btn btn-primary btn-block" />*#
<div class="form-group text-center forgottenCont">
Need help with your <a class="forgottenpwd" href="/Account/ForgotPassword.cshtml">username</a> or <a class="forgottenpwd" href="#Url.Action("ForgotPassword","Account")">password</a>?
</div>
}
</div>
<div class="text-center login-icons hidden-ph">
<i class="fa fa-2x fa-twitter"></i>
<i class="fa fa-2x fa-linkedin"></i>
<i class="fa fa-2x fa-facebook"></i>
</div>
</div>
I'm not sure why the entire textbox isn't highlighted. Can someone please tell me where I'm going wrong. Thank you.
.login-group {
background: #fff;
border: 1px solid #ccc;}
.login-group .form-control {
border: 0;}
#Nimmi: Not sure if any style is overridden here, but thanks :)

Form not submitting after form validation

I have a form in a modal window :
<div class="modal fade bs-example-modal-lg" id="vp" >
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Create Job</h4>
</div>
<div class="modal-body container-fluid">
<form id="create_job" method="post" action="?create">
<div class="form-group">
<div class="row">
<div class="col-md-4">
<input type="text" class="form-control" placeholder="Job number - Jxxxx" name="job_number">
</div>
<div class="col-md-4">
<input type="text" class="form-control" placeholder="Part number - xxxxxx" name="part_number">
</div>
<div class="col-md-2"><p class="form-control-static text-right"><b>Cable length (m):</b></p></div>
<div class="col-md-2">
<input type="text" class="form-control" placeholder="Cable" value="06" name="cable">
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" name="submitButton" class="btn btn-primary">Submit</button></form>
</div>
</div>
</div>
</div>
This is the validation js:
$(document).ready(function() {
$('#create_vpf_job').formValidation({
framework: 'bootstrap',
excluded: ':disabled',
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
job_number: {
validators: {
notEmpty: {
message: ' '
}
}
},
part_number: {
validators: {
notEmpty: {
message: ' '
}
}
},
cable: {
validators: {
notEmpty: {
message: ' '
}
}
}
}
});
});
I've look online for same problems but I haven't found a solution. The submit button doesn't submit. I'm using formvalidation.io for validation and nothing from their docs helped me.
Also tried adding with no luck
$('#create_job').submit();
Your HTML is bad formatted, and the form is closing after the container div closes, so the submit button doesn't know what to submit. Change it to:
<div id="vp" class="modal fade bs-example-modal-lg">
<div role="document" class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 id="myModalLabel" class="modal-title">Create Job</h4>
</div>
<div class="modal-body container-fluid">
<form action="?create" method="post" id="create_job">
<div class="form-group">
<div class="row">
<div class="col-md-4">
<input type="text" name="job_number" placeholder="Job number - Jxxxx" class="form-control" />
</div>
<div class="col-md-4">
<input type="text" name="part_number" placeholder="Part number - xxxxxx" class="form-control" />
</div>
<div class="col-md-2">
<p class="form-control-static text-right">
<b>Cable length (m):</b>
</p>
</div>
<div class="col-md-2">
<input type="text" name="cable" value="06" placeholder="Cable" class="form-control" />
</div>
</div>
</div>
<div class="modal-footer">
<button data-dismiss="modal" class="btn btn-default" type="button">Close</button>
<button class="btn btn-primary" name="submitButton" type="submit">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
And it will work. On this plunkr you can check that it's giving a bad-request response, which is good news, because it means the request is being done, and so, the form is being submitted once the correction made

Form submit, Input:all() not showing all inputs

RESTfully, When I submit my form and return Input:all() in the Store method I'm getting only couple inputs not all of them!!
Can anyone help me here to find out why?
and advise me if I've to use Ajax all the time to submit forms, With example please!
Store method in the Controller:
/**
* Store a newly created HOTEL in DB.
*
* #return Response
*/
public function store(/*AddNewHotelRequest $addNewHotelRequest*/)
{
if(Request::ajax()) {
if ( Session::token() !== Input::get( '_token' ) ) {
return Response::json( array(
'msg' => 'Unauthorized attempt to create setting'
) );
}
$input = Request::all();
$response = [
'status' => 'success',
'input' => $input,
'msg' => 'Hotel created successfully',
];
return Response::json( $response );
}
// return Input::all(); //with Request::all() same output
}
Form from view "create new hotel"
{!! Form::open([ 'data-remote' ,'method'=>'POST', 'action' => 'HotelsController#store', 'class' => 'panel form-horizontal','id'=>'hotelForm']) !!}
<input id="myToken" type="hidden" name="_token" value="{{ csrf_token() }}" />
<script> var _CSRT_token = "{{ csrf_token() }} " ;</script>
<div class="panel-heading">
<span class="panel-title">Adding New Hotel</span>
</div>
<div class="panel-body">
<!-- / .form-group of Errors -->
<div class="form-group">
<div class="col-sm-12">
#include('errors.list')
</div>
</div>
<!-- Hotel Name -->
<div class="form-group">
<label for="hotel_name" class="col-sm-2 control-label">Hotel name *</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="hotel_name" name="hotel_name" placeholder="Hotel name">
</div>
<p class="label label-warning label-tag">Name should be in English</p>
</div>
<!-- / .form-group of hotel_details -->
<div class="form-group">
<label for="hotel_details" class="col-sm-2 control-label">Hotel Details</label>
<div class="col-sm-8">
<textarea class="form-control" id="hotel_details" placeholder="Short description, General information or Some Details about this Hotel" rows="3"></textarea>
</div>
<p class="label label-warning label-tag">Details should be in English</p>
</div>
<!-- Hotel website -->
<div class="form-group">
<label for="hotel_website" class="col-sm-2 control-label">Website *</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="hotel_website" name="hotel_website" placeholder="http://">
</div>
</div>
<!-- / .form-group of rank -->
<div class="form-group">
<label for="rank" class="col-sm-2 control-label">Rank</label>
<div class="col-sm-1">
<input type="text" class="form-control" id="rank" placeholder="Boutique or 4">
</div>
</div>
<div class="panel colourable">
<div class="panel-body">Prices</div>
<!-- / .form-group of single_price -->
<div class="form-group">
<label for="single_price" class="col-sm-2 control-label">Single price</label>
<div class="input-group col-sm-1">
<span class="input-group-addon">€</span>
<input type="text" class="form-control room-price-group" id="single_price">
<span class="input-group-addon">.00</span>
</div>
</div>
<!-- / .form-group of double_price -->
<div class="form-group">
<label for="double_price" class="col-sm-2 control-label">Double price</label>
<div class="input-group col-sm-1">
<span class="input-group-addon">€</span>
<input type="text" class="form-control room-price-group" id="double_price">
<span class="input-group-addon">.00</span>
</div>
</div>
<!-- / .form-group of extra_bed_price -->
<div class="form-group">
<label for="extra_bed_price" class="col-sm-2 control-label">Extra Bed price</label>
<div class="input-group col-sm-1">
<span class="input-group-addon">€</span>
<input type="text" class="form-control" id="extra_bed_price">
<span class="input-group-addon">.00</span>
</div>
</div>
</div>
<div class="form-group">
<label for="facilities" class="col-sm-2 control-label">Facilities *</label>
<div class="col-sm-10">
<select id="facilities" class="col-sm-8 form-controljs-example-basic-multiple" name="facilities" multiple="multiple">
<optgroup label="Free">
#foreach($facilities as $facility)
#if(!$facility->is_surcharge)
<option class="" value="{{ $facility->id }}">{{ $facility->name }}</option>
#endif
#endforeach
</optgroup>
<optgroup label="Surcharge">
#foreach($facilities as $facility)
#if($facility->is_surcharge)
<option value="{{ $facility->id }}">{{ $facility->name }}</option>
#endif
#endforeach
</optgroup>
</select>
</div>
</div>
<div class="panel colourable">
<div class="panel-body">Address</div>
<!-- / .form-group of Country -->
<div class="form-group">
<label for="country" class="col-sm-2 control-label">Country *</label>
<div class="col-sm-2">
<select id="country" class="form-control" name="country" >
<option></option>
#foreach($countries as $country)
<option value="{{ $country->id }}" phone_code="{{ $country->phone_code }}" >{{ $country->name }}</option>
#endforeach
</select>
<p class="help-block helperQuote">Begin by choosing your country.</p>
</div>
</div>
<!-- / .form-group of Region -->
<div class="form-group">
<label for="region" class="col-sm-2 control-label">Region *</label>
<div class="col-sm-2">
<select id="region" class="form-control" name="region">
</select>
</div>
</div>
<!-- / .form-group of city -->
<div class="form-group">
<label for="city" class="col-sm-2 control-label">City *</label>
<div class="col-sm-2">
<select id="city" class="form-control" name="city">
</select>
</div>
</div>
<!-- / .form-group of rank -->
<div class="form-group">
<label for="zip" class="col-sm-2 control-label">Zip Code</label>
<div class="col-sm-1">
<input type="text" class="form-control" id="zip" placeholder="34600">
</div>
</div>
<!-- / .form-group of city -->
<div class="form-group">
<label for="address" class="col-sm-2 control-label">Hotel Address *</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="address" placeholder="Street name, number of building floor ...etc">
</div>
{{--<p class="label label-warning label-tag">Address should be in English</p>--}}
</div>
<!-- / .form-group of map -->
{{--GOOGLE MAPS--}}
<div class="form-group">
<label for="map" class="col-sm-2 control-label">Location *</label>
{{--Initialize Map--}}
<div class="col-sm-9">
<div id="map-canvas" class="" style="width: 100%; height: 350px !important;">
</div>
<p id="markerPosition" class="help-block"><i>Drag the pin to the position of the hotel </i></p>
<p id="lat" class="help-block">Latitude: 41.0694</p>
<p id="lng" class="help-block">Longitude: 29.0043</p>
<input id="latitude" type="hidden" value="37.7577">
<input id="longitude" type="hidden" value="-122.4376">
</div>
</div>
</div> <!-- End of Address Panel -->
<!-- Hotel tel -->
<div class="form-group">
<label for="country_code" class="col-sm-2 control-label">Country Code *</label>
<div class="col-sm-1">
<input type="text" class="form-control" id="country_code" name="country_code" placeholder="+90">
</div>
<label for="country_code" class="col-sm-1 control-label">Phone *</label>
<div class="col-sm-2">
<input type="text" class="form-control" id="phone" name="phone" placeholder="(___) ___-____">
</div>
<label for="extension" class="col-sm-1 control-label">Extension</label>
<div class="col-sm-1">
<input type="text" class="form-control" id="extension" name="extension" placeholder="3">
</div>
</div>
<ht/>
<!-- / .form-group of status -->
<div class="form-group">
<label for="status" class="col-sm-2 control-label">Status *</label>
<div class="col-sm-2">
<select id="status" class="form-control" name="status" >
<option value="0">Suspended</option>
<option value="1" selected>Draft</option>
<option value="2">Published</option>
</select>
<p class="help-block helperQuote"><strong>Suspended:</strong>Trash,<strong>Draft:</strong>Default,<strong>Published:Online</strong></p>
</div>
<p class="label label-warning label-tag">Only Published Hotels will be online!</p>
</div>
{{--#if (Auth::user()->isAdmin())--}}
<!-- / .form-group of publisher -->
<div class="form-group">
<label for="publisher" class="col-sm-2 control-label">Publisher *</label>
<div class="col-sm-2">
<select id="publisher" class="form-control" name="publisher" >
#foreach($publishers as $publisher)
<option value="{{ $publisher->id }}">{{ $publisher->name }} ({{$publisher->type}}) </option>
#endforeach
</select>
</div>
</div>
{{--#endif--}}
<div class="form-group" style="margin-bottom: 0;">
<div class="col-sm-offset-2 col-sm-1">
<button type="submit" class="btn btn-lg btn-primary btn-flat"><span class="btn-label icon fa fa-plus-circle"></span> Add Hotel</button>
</div>
<div id="loader" class="col-sm-1" style="display: none;"><img src="/assets/images/plugins/bootstrap-editable/loading.gif" alt="loading regions" /></div>
</div> <!-- / .form-group -->
</div>
{!! Form::Close() !!}
The output is like this:
{"_token":"PWKknjx5S9u8m98ApGDXYKqaTyF7aFZDaye9uYPm","hotel_name":"City Loft","hotel_website":"http:\/\/www.cityloft.com.tr\/","facilities":"23","country":"6","region":"3344950","city":"783593","country_code":"+355","phone":"(123) 123-1231","extension":"3123","status":"1","publisher":"1"}
you forgot name attribute for Hotel Detail and Price and might be more
<textarea class="form-control" **name="hotel_detail"** id="hotel_details" placeholder="Short description, General information or Some Details about this Hotel" rows="3"></textarea>