Humbrol2 Humbrol2 - 1 year ago 70
PHP Question

Codeigniter email validator always returns null to database

I have some code that no matter what the email submits a NULL value. I have played with every validation rule I can and it still submits a NULL value for email when submitted.


<?php php echo form_label('First Name :'); ?> <?php echo form_error('dfirstName'); ?><br>
<?php echo form_input(array('id' => 'dfirstName', 'First Name' => 'dfirstName')); ?><br>

<?php echo form_label('Last Name :'); ?> <?php echo form_error('dlastName'); ?><br />
<?php echo form_input(array('id' => 'dlastName', 'Last Name' => 'dlastName')); ?><br />

<?php echo form_label('E-mail :'); ?> <?php echo form_error('demail'); ?><br />
<?php echo form_input(array('id' => 'demail', 'e-mail' => 'demail')); ?><br />



$this->form_validation->set_error_delimiters('<div class="error">', '</div>');

//Validating firstName Field
$this->form_validation->set_rules('dfirstName', 'FirstName', 'required|min_length[4]|max_length[15]i');

//Validating lastName Field
$this->form_validation->set_rules('dlastName', 'LastName', 'required|min_length[4]|max_length[15]');

//Validating Email Field
$this->form_validation->set_rules('demail', 'e-mail', 'trim|alpha_numeric|max_length[30]');

if ($this->form_validation->run() == FALSE) {
} else {
//Setting values for tabel columns
$data = array(
'e-mail' => $this->input->post('demail'),
'LastName' => $this->input->post('dlastName'),
'FirstName' => $this->input->post('dfirstName')
//Transfering data to Model
$data['message'] = 'Data Inserted Successfully';
//Loading View
$this->load->view('acom_success', $data);

Answer Source

I know what is wrong here, the only thing you missed is the NAME.

When posting values, the PHP relies on the name of the input type. So just put the name on each input element.

This is your code

<?php echo form_input(array('id' => 'demail', 'e-mail' => 'demail')); ?><br />

Here is what's missing

<?php echo form_input(array('name' => 'demail','id' => 'demail', 'e-mail' => 'demail')); ?><br />

PHP posts are name not id :)


I have edited my answer. Please try that, If that doesn't work, can you show the whole form with the form tag?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download