[eluser]gnomishperson[/eluser]
I have this same problem...
I have a controller that loads the data into variables and sends that data onto the view file.
On the view file that contains all the loaded data also contains a form that POSTs to a different controller (or method [function]) that does the validating to determine whether or not the $_POST should be stored in the DB.
The problem is reloading the selected record from the first controller with validate errors if the validation fails, but unfortunately my trials with a redirect lead to me the conclusion the $_POST or any other data is not kept with a re-direct, and routes haven't seemed to be working for me.
This is basically my code (short-hand version):
Controller:
Code:
<?php
class Pathologist extends Controller
{
function Pathologist()
{
parent::Controller();
// VALIDATION SETTINGS
$this->load->library('validation');
$fields['pathologic_description'] = 'Final Pathologic Description';
$fields['microscopic_description'] = 'Microscopic Description';
$this->validation->set_fields($fields);
}
/**
* Displays home page of Admin Console
*
*/
function index()
{
//listing records as links to details of record based on logged in user.
}
/**
* View record details
*
* @param record id $id
*/
function show($id = '')
{
($id == '' ? $id = $this->uri->segment(4) : $id);
$query = $this->getCaseById($id);
if ($query->num_rows() == 1)
{
$row = $query->row();
$data['pathologist']['id'] = $row->id;
/* Rest of fields being set
** $data['pathologist']['etc']
*/
//Comments
$comments = $this->getComments($row->id);
//rest of comment code would be here
//Function called from form within view file.
function findings()
{
$id = $this->input->post('id');
$case_id = $this->input->post('case_id');
$final = $this->input->post('pathologic_description');
$micro = $this->input->post('microscopic_description');
$save = $this->input->post('save');
$submit = $this->input->post('submit');
$rules['pathologic_description'] = "trim|required|xss_clean";
$rules['microscopic_description'] = "trim|xss_clean";
$this->validation->set_rules($rules);
if ($this->validation->run() == FALSE)
{
$this->show($id);
}
else
{
if (!$submit)
{
echo 'Attempting to Save';
//$this->saveCase($id, $final, $micro);
}
else
{
echo 'Trying to submit';
//$this->submitCase($id, $final, $micro);
}
}
View File:
Code:
<?php $rows = 5; $cols = 88; ?>
<h2><?=$action?></h2>
<p class="error"><?=$this->validation->error_string?></p>
<!--USERPROFILE DATA-->
<!-- START DETAILS DATA-->
<div class="details">
<fieldset>
<legend>Case #: <?=$pathologist['case_id']?></legend>
<ul>
<li>List of Items to Display</li>
</ul>
</fieldset>
<fieldset>
<legend>Pathologist Findings</legend>
//This is the form in question
<?=form_open('pathologist/'.$controller.'/findings')?>
<p>
Final Pathologic Description<br />
<?=form_textarea(array('name' => 'pathologic_description',
'id' => 'pathologic_description',
'value'=> (isset($this->validation->pathologic_description)) ? ($this->validation->pathologic_description) : ($pathologist['pathologic_description']),
'rows' => $rows,
'cols' => $cols
))?>
</p>
<p>
Microscopic Description<br />
<?=form_textarea(array('name' => 'microscopic_description',
'id' => 'microscopic_description',
'value'=> (isset($this->validation->microscopic_description)) ? ($this->validation->microscopic_description) : ($pathologist['microscopic_description']),
'rows' => $rows,
'cols' => $cols
))?>
</p>
<?=form_hidden('id', $pathologist['id'])?>
<?=form_hidden('case_id', $pathologist['case_id'])?>
<?=form_submit(array('class' => 'submit',
'name' => 'save',
'id' => 'save',
'value' => 'Save'
))?>
<?=form_submit(array('class' => 'submit',
'name' => 'submit',
'id' => 'submit',
'value' => 'Submit Findings'
))?>
<?=form_close()?>
</fieldset>
<fieldset>
<legend>Comments</legend>
//Comments section
</fieldset>
<?=form_open('pathologist/'.$controller)?>
<?=form_submit(array('class'=>'submit',
'name'=>'back',
'id'=>'submit',
'value'=>'Back'
))?>
<?=form_close()?>
</div>
Basically my URI ends up being
http://base.url/pathologist/pathologist/findings when I need it to be
http://pathologist/pathologist/show/$case_id/ if the validation fails.
Still very much a rough draft, but my problem is still the same as the one mentioned above.