Beste,
Ik ben bezig met het framework codeigniter om er een cms van te maken,
echter krijg ik het niet voor elkaar om te kijken welke radio button gechecked is.
Als in de database een Ja staat moet de ja checked zijn en de Nee niet, echter doet hij het niet
Stukje code:
PHP
<?php if($configuratie[0]['offline'] = 'Ja')
{
echo'Ja <input type="radio" name="offline" value="Ja" checked>
Nee <input type="radio" id="" name="offline" value="Nee" >';
}
else if($configuratie[0]['offline'] = 'Nee')
{
echo'Ja <input type="radio" name="offline" value="Ja">
Nee <input type="radio" id="" name="offline" value="Nee" checked>';
}
?>
Toon Meer
Hij blijft telkens op ja staan....
Wie o wie kan mij helpen?
Controller:
PHP
<?php
class Admin_configuratie extends CI_Controller {
/**
* name of the folder responsible for the views
* which are manipulated by this controller
* @constant string
*/
const VIEW_FOLDER = 'admin/configuratie';
/**
* Responsable for auto load the model
* @return void
*/
public function __construct()
{
parent::__construct();
$this->load->model('configuratie_model');
if(!$this->session->userdata('is_logged_in')){
redirect('admin/login');
}
}
/**
* Load the main view with all the current model model's data.
* @return void
*/
public function index()
{
//pagination settings
$config['per_page'] = 5;
$config['base_url'] = base_url().'admin/configuratie';
$config['use_page_numbers'] = TRUE;
$config['num_links'] = 20;
$config['full_tag_open'] = '<ul>';
$config['full_tag_close'] = '</ul>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a>';
$config['cur_tag_close'] = '</a></li>';
//limit end
$page = $this->uri->segment(3);
//fetch sql data into arrays
$data['configuratie'] = $this->configuratie_model->get_configuratie();
//initializate the panination helper
$this->pagination->initialize($config);
//load the view
$data['main_content'] = 'admin/configuratie/list';
$this->load->view('includes/template', $data);
}
//index
public function update()
{
//if save button was clicked, get the data sent via post
if ($this->input->server('REQUEST_METHOD') === 'POST')
{
//form validation
$this->form_validation->set_rules('websitenaam', 'Websitenaam', 'trim|required');
$this->form_validation->set_error_delimiters('<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a><strong>', '</strong></div>');
//if the form has passed through the validation
if ($this->form_validation->run())
{
$data_to_store = array(
'websitenaam' => $this->input->post('websitenaam'),
'offline' => $this->input->post('offline'),
'offline_bericht' => $this->input->post('offline_bericht'),
'metabeschrijving' => $this->input->post('metabeschrijving'),
'metatrefwoorden' => $this->input->post('metatrefwoorden'),
);
//if the insert has returned true then we show the flash message
if($this->configuratie_model->update_configuratie($data_to_store) == TRUE){
$this->session->set_flashdata('flash_message', 'updated');
}else{
$this->session->set_flashdata('flash_message', 'not_updated');
}
redirect('admin/configuratie/update');
}//validation run
}
//if we are updating, and the data did not pass trough the validation
//the code below wel reload the current data
//product data
$data['configuratie'] = $this->configuratie_model->get_configuratie();
//load the view
$data['main_content'] = 'admin/configuratie/edit';
$this->load->view('includes/template', $data);
}//update
}
Toon Meer
Model:
PHP
<?php
class Configuratie_model extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function get_configuratie()
{
$this->db->select('*');
$this->db->from('configuratie');
$query = $this->db->get();
return $query->result_array();
}
function update_configuratie($data)
{
$this->db->update('configuratie', $data);
$report = array();
$report['error'] = $this->db->_error_number();
$report['message'] = $this->db->_error_message();
if($report !== 0){
return true;
}else{
return false;
}
}
}
?>
Toon Meer
View:
PHP
<div class="container top">
<ul class="breadcrumb">
<li>
<a href="<?php echo site_url("admin"); ?>">
<?php echo ucfirst($this->uri->segment(1));?>
</a>
<span class="divider">/</span>
</li>
<li>
<a href="<?php echo site_url("admin").'/'.$this->uri->segment(2); ?>">
Configuratie
</a>
<span class="divider">/</span>
</li>
<li class="active">
<a href="#">Bewerken</a>
</li>
</ul>
<div class="page-header">
<h2>
Configuratie
</h2>
</div>
<?php
//flash messages
if($this->session->flashdata('flash_message')){
if($this->session->flashdata('flash_message') == 'updated')
{
echo '<div class="alert alert-success">';
echo '<a class="close" data-dismiss="alert">×</a>';
echo '<strong>Succes!</strong> gebruiker is succesvol aangepast';
echo '</div>';
}else{
echo '<div class="alert alert-error">';
echo '<a class="close" data-dismiss="alert">×</a>';
echo '<strong>Oh snap!</strong> change a few things up and try submitting again.';
echo '</div>';
}
}
?>
<?php
//form data
$attributes = array('class' => 'form-horizontal', 'id' => '');
//form validation
echo validation_errors();
echo form_open('admin/configuratie/update', $attributes);
?>
<fieldset>
<div class="control-group">
<label for="inputError" class="control-label">Websitenaam</label>
<div class="controls">
<input type="text" id="" name="websitenaam" value="<?php echo $configuratie[0]['websitenaam']; ?>" >
</div>
<label for="inputError" class="control-label">Website offline</label>
<div class="controls">
<?php if($configuratie[0]['offline'] = 'Ja')
{
echo'Ja <input type="radio" name="offline" value="Ja" checked>
Nee <input type="radio" id="" name="offline" value="Nee" >';
}
else if($configuratie[0]['offline'] = 'Nee')
{
echo'Ja <input type="radio" name="offline" value="Ja">
Nee <input type="radio" id="" name="offline" value="Nee" checked>';
}
?>
<br /><br />
</div>
<label for="inputError" class="control-label">Offline bericht</label>
<div class="controls">
<textarea name="offline_bericht" value="<?php echo $configuratie[0]['offline_bericht']; ?>"><?php echo $configuratie[0]['offline_bericht']; ?></textarea>
</div>
<label for="inputError" class="control-label">Meta beschrijving</label>
<div class="controls">
<textarea name="metabeschrijving" value="<?php echo $configuratie[0]['metabeschrijving']; ?>"><?php echo $configuratie[0]['metabeschrijving']; ?></textarea>
</div>
<label for="inputError" class="control-label">Meta trefwoorden</label>
<div class="controls">
<textarea name="metatrefwoorden" value="<?php echo $configuratie[0]['metatrefwoorden']; ?>"><?php echo $configuratie[0]['metatrefwoorden']; ?></textarea>
</div>
<div class="form-actions">
<button class="btn btn-primary" type="submit">Wijzigen</button>
</div>
</fieldset>
<?php echo form_close(); ?>
</div>
Toon Meer