[eluser]Lexperts[/eluser]
Hi,
I try too select the manufacturer_id on my update page. But it is not working. When a want to get the values of others. Then it works fine (title, size, price).
Code:
$this->validation->title = quotes_to_entities($record->title);
$this->validation->manufacturer_id = $record->manufacturer_id;
$this->validation->size = quotes_to_entities($record->size); <-- There is a value, but it will not be selected in my view
$this->validation->price = $this->cart->format_number($record->price);
This is my controller:
Code:
function update(){
$data['page_title'] = 'Artikel updaten';
$data['meta'] = array(
array('name' => 'description', 'content' => 'Mailgroepen'),
array('name' => 'keywords', 'content' => 'mailen, nieuws, mailsysteem'),
array('name' => 'robots', 'content' => 'no-cache'),
array('name' => 'Content-type', 'content' => 'text/html; charset=utf-8', 'type' => 'equiv')
);
$query = $this->manufacturer_model->get_records();
$data['manufacturers'] = $query;
$product_id = $this->uri->segment(3, FALSE);
if(!$product_id){
redirect('product');
}
if($query = $this->product_model->get_record($product_id)){
$record = $query;
} else {
redirect('product');
}
$this->_set_fields();
$this->_set_rules();
$data['action'] = site_url('product/update/' . $product_id);
$data['submit_value'] = 'Opslaan';
$this->validation->title = quotes_to_entities($record->title);
$this->validation->manufacturer_id = $record->manufacturer_id;
$this->validation->size = quotes_to_entities($record->size);
$this->validation->price = $this->cart->format_number($record->price);
if ($this->validation->run() == FALSE){
$data['view'] = 'product/form';
} else {
$data = array(
'manufacturer_id' => $this->input->post('manufacturer_id', TRUE),
'title' => $this->input->post('title', TRUE),
'size' => $this->input->post('size', TRUE),
'price' => $this->input->post('price', TRUE)
);
$this->product_model->update_record($data, $product_id);
$this->session->set_flashdata('messages', 'Het artikel is succesvol geupdate.');
$this->session->set_flashdata('messages_css', 'succes');
redirect('product');
}
$this->load->view('template', $data);
}
function _set_fields(){
$fields['title'] = 'title';
$fields['manufacturer_id'] = 'manufacturer_id';
$fields['size'] = 'size';
$fields['price'] = 'price';
$this->validation->set_fields($fields);
}
function _set_rules(){
$rules['title'] = 'trim|required';
$rules['manufacturer_id'] = 'callback_manufacturer_check';
$rules['size'] = 'trim|required';
$rules['price'] = 'trim|required|numeric';
$this->validation->set_rules($rules);
$this->validation->set_error_delimiters('<div class="notification error">', '</div><div class="space"></div>');
}
function manufacturer_check(){
$this->validation->set_message('manufacturer_check', 'Kies een merk');
return $this->manufacturer_model->check_record($this->input->post('manufacturer_id', TRUE));
}
This is my view
Code:
<?php echo $this->validation->error_string; ?>
<div class="form">
<?=form_open($action)?>
<fieldset>
<legend>Algemene gegevens</legend>
<div class="row"><label>Artikel naam:</label>
<input type="text" name="title" value="<?php echo $this->validation->title; ?>" /></div>
<div class="row"><label>Merk:</label>
<select name="manufacturer_id">
<option value="FALSE">Kies een merk</option>
<?php foreach($manufacturers as $manufacturer):?>
<option value="<?=$manufacturer->manufacturer_id?>" <?php echo $this->validation->set_select('manufacturer_id', $manufacturer->manufacturer_id);?>><?=quotes_to_entities($manufacturer->title)?></option>
<?php endforeach; ?>
</select>
</div>
<div class="row"><label>Maat:</label>
<input type="text" name="size" value="<?php echo $this->validation->size; ?>" /></div>
<div class="row"><label>Prijs:</label>
<input type="text" name="price" value="<?php echo $this->validation->price; ?>" /></div>
</fieldset>
<div class="space"></div>
<div class="space"></div>
<input class="form-submit" type="submit" value="<?=$submit_value?>" />
</form>
Thanks in advance!
Lex