Irene Baluis Irene Baluis - 3 months ago 14
PHP Question

Data does not save and not displaying any error - Codeigniter

The data doesn't save without prompting any errors in my code

Here is my code in my Controller

function saveDebit(){
$jevseries=$this->input->post('series');
$account='debit';
$count='1';
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules('accountName', 'Account Name', 'required');
$this->form_validation->set_rules('amountDebit', 'Amount', 'required|numeric');

$this->formValidation();
if ($this->form_validation->run() == FALSE) {
$this->entryAccount($jevseries);
} else {
$debitData = array(
'Series' => $jevseries,
'AccountCode' => $this->input->post('accountName'),
'Account' => $account,
'Amount' => $this->input->post('amountDebit'),
'Count' => $count);

$this->Jev_model->entryDebit($debitData);
}


}

Model

function entryDebit($debitData){
$this->db->insert('generalaccount', $debitData);
}


This is my View

<?php echo form_open('Jev/saveDebit'); ?>
<table class="jev_entry" id="jev_entry">
<tr>
<td>Debit</td>
<?php echo form_hidden('series', $series);?>
<td><?php
$account_array = array();
foreach($accountNames as $account ){
$account_array []= $account->accountName;
}

echo form_dropdown('accountName', $account_array,'', 'class="form-control"');

?></td>
</tr>
<tr>
<td>Amount</td>
<td><?php echo form_input('amountDebit','', 'class="form-control"');?><div class="error"><?php echo form_error('amountDebit'); ?></div></td>
</tr>
<tr>
<td></td>
<td align="center"><?php echo '<center>'. form_submit('submit','Save').'</center>'; ?> </td>
</tr>
</table>


I don't know where is the error in this lines.. Your help is very much appreciated.

Answer

Okay i have found out what is wrong, The form_input of codeigniter only gives the form with a label. It does not give a name therefore we cannot post it since it doesn't have a name. Do this :)

$data = array(
        'name'          => 'username',
        'id'            => 'username',
        'value'         => 'johndoe',
        'maxlength'     => '100',
        'size'          => '50',
        'style'         => 'width:50%'
);

echo form_input($data);

It's like that and we post the name. Of course you can remove some parameters. More info in the form helper user guide in codeigniter :)

Godluck meyt

Comments