I have a form which is not working. I want to delete to delete a record from my database using a certain form. The user first selects the department which he wants to delete an entity from and is redirected to another form which allows him to choose the entity he wants to delete. This form is populated by data depending on the user's choice from the first form. When I try to submit my form notthing happens. I have a similar problem with my search form. Here is my code
Here is view code where the user selects the department which he wants to delete from
Code:
<h1 align="center">DELETE COLLEGE OFFICES</h1>
<div align="center">
<p><?php echo validation_errors(); ?></p>
<p>Note: Deleting a College Office will delete all other data(phones) associated with the deleted office</p>
Proceed with caution
<p><?php echo form_open('phones/chooseOffice') ?></p>
<table width="303" border="1">
<tr>
<th width="119" scope="row"><?php echo form_label('Select Department', 'department'); ?></th>
<td width="168"><?php
$options = array();
foreach($departments as $option){
$options[$option['id']] = $option['names'];
}
//$options = $tmp;
echo form_dropdown('departments', $options, ''); ?></td>
</tr>
<tr>
<th colspan="2" scope="row"><p><?php echo form_submit('submit', 'Continue to Department Offices') ?></p></th>
</tr>
</table>
<p><?php echo form_close(); ?>
</p>
<p> </p>
<p>To delete a College Number click below</p>
<p><a href="/ci_directory/index.php/showdeleteform/2">CLICK HERE</a></p>
</div>
Here is the controller whhich the form above submits to
Code:
//shows the form to select office data to delete
public function chooseOffice()
{
$data['offices'] = $this->contacts_model->search_offices($this->input->post('departments'));
$this->load->view('templates/header' );
$this->load->view('showcollegeoffices.php', $data);
$this->load->view('templates/footer');
}
Here is the view displayed by the chooseOffice function
Code:
<?php $this->load->helper('form');
//loop through the returned array and disoplay the offices ?>
<?php foreach ($offices as $office) : ?>
<?php echo $office['names']; ?>
<?php form_open('phones/deleteOffice') ?>
<?php $data = array(
'name' => 'office',
'id' => '',
'value' => $office['id'],
'maxlength' => '150',
'size' => '100',
'style' => 'width:50%');
//echo form_input($data); ?>
<?php echo form_submit('submit', 'Delete Office'); ?>
<?php echo form_close(); ?>
<?php endforeach ?>
Here is controller function the view above is suppossed to submit the form to.
Code:
//deletes an office and all its contacts
public function deleteOffice()
{
$this->load->helper('form');
//if the delete function works show the delete department view with a success message
if( $this->contacts_model->delete_office($this->input->post('office')))
{
$data['title'] = 'Delete College Office';
$this->index();
}
else{
// show the delete department view with an unsuccessful message
$data['title'] = 'Delete College Department';
$data['departments'] = $this->contacts_model->get_departments();
$data['message'] =' All Data Has Been Deleted';
$data['offices'] = $this->contacts_model->search_offices($this->input->post('departments'));
$this->load->view('templates/header' );
$this->load->view('showcollegeoffices.php', $data);
$this->load->view('templates/footer');
}
}