[eluser]Unknown[/eluser]
I have been trying to fix this issue for days, with no luck, so I hope someone can help me. I am using version 2.1.4, but have tried 2.1.3 and 2.1.2 as well. I have been using CodeIgniter for years and never run into anything like this.
I am using the Form_Validation class to do basic validation on my site. When going into Form_validation.php and output $this->_field_data it returns with all of my information from within set_rules and run, but if I try to output $this->_field_data in set_value it returns an empty array.
I auto load the form_validation library and the form/url helpers.
Controller
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Stream extends CI_Controller
{
var $data = array();
var $stream_template = "templates/stream";
function __construct() { parent::__construct(); }
public function create($type = 'headline')
{
// Verify Valid Type
if(in_array($type, array('article', 'cluster', 'headline')))
{
$this->data['type'] = $type;
$this->form_validation->set_rules('headline', 'Headline', 'trim|required|xss_clean');
if($type == 'article')
{
$this->form_validation->set_rules('article', 'Article', 'trim|xss_clean');
}
$this->form_validation->set_rules('place', 'Location', 'trim|xss_clean');
$this->form_validation->set_rules('placeId', 'Place ID', 'trim|xss_clean');
$this->form_validation->set_rules('categoryId[]', 'Category', 'trim|xss_clean|callback_one_checkbox_set');
$this->form_validation->set_rules('tags', 'Tags', 'trim|xss_clean');
if($this->form_validation->run())
{
// Set Variables for Database Insert
$post = $this->input->post();
$insert = array(
'headline' => $post['headline'],
'tags' => $post['tags']
);
// Set Location
if($post['placeId']) { $insert['placeId'] = $post['placeId']; }
elseif($post['place'])
{
// Find/Create Location
if($place = $this->streams_model->places_get_single(array('place' => $post['place'], 'deleted' => 0))) { $insert['placeId'] = $place->placeId; }
else { $insert['placeId'] = $this->streams_model->places_add(array('place' => $post['place'])); }
}
// Insert to Proper Table
if($type == 'article')
{
$insert['article'] = $post['article'];
$id = $this->streams_model->articles_add($insert);
$this->assets_model->metadata_add_array(array($type.'Id' => $id), $post['categoryId']);
}
else
{
if($type == 'cluster') { $id = $this->streams_model->clusters_add($insert); }
else { $id = $this->streams_model->headlines_add($insert); }
$this->assets_model->metadata_add_array(array($type.'Id' => $id), $post['categoryId']);
// Run Automated Compare
$this->streams_model->streams_compare($type, $id);
}
redirect($type.'/'.$id);
}
else { $this->create_view(); }
}
else { redirect('stream'); }
}
private function create_view()
{
$this->data['title'] = "Create ".ucfirst($this->data['type']);
$this->data['page'] = "stream-create-".$this->data['type'];
$this->load->view($this->stream_template, $this->data);
}
function one_checkbox_set($value)
{
$this->form_validation->set_message('one_checkbox_set', 'Atleast one %s must be selected.');
return false;
}
}
/* End of file stream.php */
/* Location: ./application/controllers/stream.php */
View:
Code:
<section class="create">
<h2>Create Headline</h2>
<?php echo form_open('headline/create'); ?>
<?php echo validation_errors(); ?>
<ul>
<li class="headline">
<?php echo form_input('headline', set_value('headline'), 'placeholder="Headline"'); ?></li>
<li class="place">
<?php echo form_input('place', set_value('place'), 'placeholder="Location" class="place-ac"'); ?>
<?php echo form_hidden('placeId', set_value('placeId')); ?></li>
<?php $tags = array('name' => 'tags', 'value' => set_value('tags'), 'placeholder' => 'Tags (comma seperated)', 'rows' => '5'); ?>
<li class="tags"><?php echo form_textarea($tags); ?></li>
<li class="categories">
<?php foreach($categories as $key => $value): ?>
<?php $isset = in_array($key, set_value('categoryId[]')?set_value('categoryId[]'):array())?true:false; ?>
<?php echo form_checkbox('categoryId[]', $key, $isset, 'id="category-'.$key.'"'); ?>
<label for="category-<?php echo $key; ?>"><?php echo $value; ?></label>
<?php endforeach; ?>
</li>
<li class="submit"><button type="submit">Submit</button></li>
</ul>
<?php echo form_close(); ?>
</section>
Also, one_checkbox_set is suppose to return false, so that I can test things.