[eluser]Unknown[/eluser]
Any help here would be much appreciated. I am trying to pass form variables through javascript to a CI controller to update a database. If I set up a form and submit it, all goes fine. If I use JS, variables end up being empty.
JS:
Code:
function add_veh() {
var theurl = "https://www.domain.com/backoffice/customer/opto_vehicle/";
var cust_id = $('cust_id').get('value');
var veh_year = $('veh_year').get('value');
var veh_make = $('veh_make').get('value');
var veh_model = $('veh_model').get('value');
var veh_mileage = $('veh_mileage').get('value');
var opts = "cust_id="+cust_id+"&veh;_year="+veh_year+"&veh;_make="+veh_make+"&veh;_model="+veh_model+"&veh;_mileage="+veh_mileage;
var myHTMLRequest = new Request.HTML({url: theurl, update: 'vehicles-div'}).post(opts);
}
HTML:
Code:
<form id="adder_veh" name="adder_veh" action="[removed]add_veh()" method="post" enctype="multipart/form-data">
<input type="hidden" id="cust_id" name="cust_id" value="<?= $cust_id ?>">
<table>
<tr>
<td>Year</td><td>Make</td><td>Model</td><td>Mileage</td>
</tr>
<tr>
<td><input type="text" name="veh_year" id="veh_year" value="<?= set_value('year') ?>" /></td>
<td><input type="text" name="veh_make" id="veh_make" value="<?= set_value('make') ?>"/></td>
<td><input type="text" name="veh_model" id="veh_model" value="<?= set_value('model') ?>" ></td>
<td><input type="text" name="veh_mileage" id="veh_mileage" value="<?= set_value('mileage') ?>" /></td>
<td><input type="submit" name="add_vehicle_form" id="add_vehicle_form" value="Add" />
</td>
</tr>
</table>
</form>
CI Controller:
Code:
class Customer extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->library(array('encrypt', 'form_validation'));
$this->load->database();
$this->load->helper(array('form', 'url'));
}
function opto_vehicle() {
$this->load->model('backoffice');
$this->load->helper(array('form', 'url'));
$cust_id=$this->input->post('cust_id');
$year=$this->input->post('veh_year');
$make=$this->input->post('veh_make');
$model=$this->input->post('veh_model');
$mileage=$this->input->post('veh_mileage');
$result = $this->backoffice->add_vehicle($cust_id, $year, $make, $model, $mileage);
$data['vehicles'] = $this->backoffice->get_customer_vehicles($cust_id);
$data['cust_id'] = $cust_id;
$this->load->view('edit_vehicle',$data);
}
}
Firebug shows the post variables as I would expect them. Everything runs, but the model inserts empty values in the database.