[eluser]billmce[/eluser]
Thanks for the row_array tip and all your suggestions ... but unfortunately the issue remains.
I am definitely in the right block -- which I've confirmed by adding 'echo's.
I tried your new code ... unfortunately the result yields no difference.
--
<li><label for="Company">Company:</label>
<input type="text" name="Company" value=" <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: Notice</p>
<p>Message: Undefined variable: Company</p>
<p>Filename: views/creditor_edit_view.php</p>
<p>Line Number: 59</p>
</div>Test Company Name" /></li>
--
You can see that the <div> is being injected inside the value ... instead of the result of the set_value command (here "Test Company Name").
[eluser]billmce[/eluser]
Don't forget, if I use 2 views (one for first time edit, another after form_validations) -- eliminating the set_value command -- everything works perfectly.
[eluser]billmce[/eluser]
I checked my CSS and the div string is unlike anything I've got in my css file.
[eluser]Ben Edmunds[/eluser]
do an echo on $Company the first time through in the view and see if it is set. Also, do a print_r($data) in the controller.
[eluser]billmce[/eluser]
I inserted the following in the view:
<?php echo "Variable is $Company and set_value is " . set_value('Company');?>
On first entry (original edit) to the view
"Variable is Test Company and set_value is "
On 2nd and subsequent views (I've appended 'Modified' to the original company name)
"Variable is and set_value is Test Company Modified "
--
I added 'print_r($data);' twice in the controller -- in the sections loading the view.
On first entry:
Array ( [css] => http://localhost/cif/application/css/styles.css [images] => http://localhost/cif/application/images/ [jss] => http://localhost/cif/application/jss/jquery.js [base] => http://localhost/cif/ [robots] => [title] => Creditors [pagetitle] => Screen for Creditors [UniqContactID] => 1230 [CategoryID] => 1 [Company] => Test Company [SearchName] => Test Company [Building] => [StreetNumber] => 7100 [StreetNumberSuffix] => [Unit] => [StreetName] => Test Ave., Suite 400, [StreetType] => [StreetDirection] => [Municipality] => Markham [ProvinceState] => ON [PostalCodeZip] => H0H 5J2 [Country] => CA [LTCCode] => 9 [GovernmentCode] => N [PrivacyPolicyExempt] => 0 [ProofOfClaimRequired] => 0 [AdditionalInformation] => [dataphones] => CI_DB_mysql_result Object ( [conn_id] => Resource id #44 [result_id] => Resource id #59 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 1 [row_data] => ) [BtnSaveCredType] => Save Changes )
On subsequent edits (after validation fails):
Array ( [css] => http://localhost/cif/application/css/styles.css [images] => http://localhost/cif/application/images/ [jss] => http://localhost/cif/application/jss/jquery.js [base] => http://localhost/cif/ [robots] => [title] => Creditors [pagetitle] => Screen for Creditors [BtnSaveCredType] => Save Revised Changes )
--
I hope that helps ... thanks for sticking with me on this.
[eluser]Ben Edmunds[/eluser]
I'm probably missing something because I'm pretty busy right now but try this...
Code: function edit_creditor($UniqContactID = '')
{
/**
* Edit a creditor given then UniqContactID
* throws to an editing screen
*/
$this->load->helper('form');
$this->load->model('creditors_model');
$this->load->helper('form');
$this->load->library('form_validation');
$data['css'] = $this->css;
$data['images'] = $this->images;
$data['jss'] = $this->jss;
$data['base'] = $this->base;
$data['robots'] = '<meta name="robots" content="noindex,nofollow">';
$data['title']="Creditors"; //shows up on tab
$data['pagetitle']="Screen for Creditors"; //top of page body
$this->form_validation->set_rules('CategoryID','CategoryID', 'required');
$this->form_validation->set_rules('Company', 'Company', 'required|min_length[80]');
$this->form_validation->set_rules('SearchName', 'SearchName', 'required');
$this->form_validation->set_rules('Building','Building', 'required');
$this->form_validation->set_rules('StreetNumber','StreetNumber', 'required');
$this->form_validation->set_rules('Unit','Unit', 'required');
$this->form_validation->set_rules('StreetNumberSuffix','StreetNumberSuffix', 'required');
$this->form_validation->set_rules('StreetName','StreetName', 'required');
$this->form_validation->set_rules('StreetType','StreetType', 'required');
$this->form_validation->set_rules('StreetDirection','StreetDirection', 'required');
$this->form_validation->set_rules('Municipality','Municipality', 'required');
$this->form_validation->set_rules('ProvinceState','ProvinceState', 'required');
$this->form_validation->set_rules('PostalCodeZip','PostalCodeZip', 'required');
$this->form_validation->set_rules('Country','Country', 'required');
$this->form_validation->set_rules('LTCCode','LTCCode', 'required');
$this->form_validation->set_rules('GovernmentCode','GovernmentCode', 'required');
$this->form_validation->set_rules('PrivacyPolicyExempt','PrivacyPolicyExempt', 'required');
$this->form_validation->set_rules('ProofOfClaimRequired','ProofOfClaimRequired', 'required');
$this->form_validation->set_rules('AdditionalInformation','AdditionalInformation', 'required');
$this->form_validation->run(); //will fail on run thru because no post data
//We haven't got any data yet .. ie) first time in record.
$creditors = $this->creditors_model->get_creditor($UniqContactID)->row_array();
$data = array_merge($data, $creditors);
if(empty($_POST['BtnSaveCredType']))
{
$data['BtnSaveCredType'] = 'Save Changes';
// now go in and bring up the form.
$this->load->view('header_view',$data);
$this->load->view('menu_view');
$this->load->view('creditor_edit_view', $data);
$this->load->view('footer_view',$data);
}
else
{
//We're into re-editing
$data['BtnSaveCredType'] = 'Save Revised Changes';
if ($this->form_validation->run() == FALSE)
{
$this->load->view('header_view',$data);
$this->load->view('menu_view');
$this->load->view('creditor_edit_view', $data);
$this->load->view('footer_view',$data);
}
else
{
// call model to save data here.
}
};
}
[eluser]billmce[/eluser]
I had to move a couple lines around to avoid an error.
I moved the following two lines under the if conditon.
if(empty($_POST['BtnSaveCredType']))
{
//We haven't got any data yet .. ie) first time in record.
$creditors = $this->creditors_model->get_creditor($UniqContactID)->row_array();
$data = array_merge($data, $creditors);
but ...
No change.
controller
==========
Code: function edit_creditor($UniqContactID = '')
{
/**
* Edit a creditor given then UniqContactID
* throws to an editing screen
*/
$this->load->helper('form');
$this->load->model('creditors_model');
$this->load->helper('form');
$this->load->library('form_validation');
$data['css'] = $this->css;
$data['images'] = $this->images;
$data['jss'] = $this->jss;
$data['base'] = $this->base;
$data['robots'] = '<meta name="robots" content="noindex,nofollow">';
$data['title']="Creditors"; //shows up on tab
$data['pagetitle']="Screen for Creditors"; //top of page body
$this->form_validation->set_rules('CategoryID','CategoryID', 'required');
$this->form_validation->set_rules('Company', 'Company', 'required|min_length[80]');
$this->form_validation->set_rules('SearchName', 'SearchName', 'required');
$this->form_validation->set_rules('Building','Building', 'required');
$this->form_validation->set_rules('StreetNumber','StreetNumber', 'required');
$this->form_validation->set_rules('Unit','Unit', 'required');
$this->form_validation->set_rules('StreetNumberSuffix','StreetNumberSuffix', 'required');
$this->form_validation->set_rules('StreetName','StreetName', 'required');
$this->form_validation->set_rules('StreetType','StreetType', 'required');
$this->form_validation->set_rules('StreetDirection','StreetDirection', 'required');
$this->form_validation->set_rules('Municipality','Municipality', 'required');
$this->form_validation->set_rules('ProvinceState','ProvinceState', 'required');
$this->form_validation->set_rules('PostalCodeZip','PostalCodeZip', 'required');
$this->form_validation->set_rules('Country','Country', 'required');
$this->form_validation->set_rules('LTCCode','LTCCode', 'required');
$this->form_validation->set_rules('GovernmentCode','GovernmentCode', 'required');
$this->form_validation->set_rules('PrivacyPolicyExempt','PrivacyPolicyExempt', 'required');
$this->form_validation->set_rules('ProofOfClaimRequired','ProofOfClaimRequired', 'required');
$this->form_validation->set_rules('AdditionalInformation','AdditionalInformation', 'required');
$this->form_validation->run(); //will fail on run thru because no post data
if(empty($_POST['BtnSaveCredType']))
{
//We haven't got any data yet .. ie) first time in record.
$creditors = $this->creditors_model->get_creditor($UniqContactID)->row_array();
$data = array_merge($data, $creditors);
$data['BtnSaveCredType'] = 'Save Changes';
// now go in and bring up the form.
$this->load->view('header_view',$data);
$this->load->view('menu_view');
$this->load->view('creditor_edit_view', $data);
$this->load->view('footer_view',$data);
}
else
{
//We're into re-editing
$data['BtnSaveCredType'] = 'Save Revised Changes';
if ($this->form_validation->run() == FALSE)
{
$this->load->view('header_view',$data);
$this->load->view('menu_view');
$this->load->view('creditor_edit_view', $data);
$this->load->view('footer_view',$data);
}
else
{
// call model to save data here.
}
};
}
[eluser]Ben Edmunds[/eluser]
ugh...
email me at [email protected] and we'll figure it out
[eluser]billmce[/eluser]
Ahhh ... we got it. Thanks to Ben and Brennan McEachran.
The crux of the problem is that set_value expects that both of the values passed to it have some value.
On the second pass, after validation failure, there is no value in the variables because I only got the data once .. the first pass when I actually need it to populate the view.
As Ben and Brennan noticed ... I had to re-retrieve the data on the 2nd and subsequent passes (even though I'm not going to use it) in order to keep set_value happy.
So, with the addition of a hidden value on the form to keep track of the $UniqContactID that was originally passed to the function -- on all subsequent iterations set_value has values in both
'Company' and $Company and behaves as advertised.
I'd suggest that set_values optional parameter behave differently ... but hey, it's now working.
Thanks Ben and Brennan ... I can feel my headache slowly subsiding.
[eluser]Ben Edmunds[/eluser]
Glad you got it!
|