Welcome Guest, Not a member yet? Register   Sign In
My form is not submitting
#1

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>&nbsp;</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');
      }
   }
Reply
#2

Are the forms in both views not submitting, or just the forms in the second view?

If the form in the first view submits, it's because your browser is being very lenient with your HTML, as your form_open() and form_close() calls should not be enclosed in paragraph tags.

In the second view, I don't think the forms are going to have anything to submit if the inputs are commented out, and you need to either set the id to a unique value for each input, or leave it out of the $data array.

Use "View Source" or your browser's debugger to check your HTML and make sure you're getting the output you expect, because there are a number of issues with the HTML in your first view. The second view looks like it contains nothing but PHP, so you could take out all of the PHP tags except for the first opening tag, which might make it easier to read, if nothing else.
Reply
#3

(This post was last modified: 02-04-2015, 01:12 AM by andyblem.)

the first view is submitting. the second view is not submitting. what i am trying to do is the second view is populated with data from the database., like a list of offices in the database. beside every office they should be a delete button which allows the user to delete that office.My form is not empty. It has a text field which I initilize using the office's id from the database. I didn't want the user to be able to change this value so I commented out "echo" part of the text field
Reply
#4

(This post was last modified: 02-04-2015, 02:45 AM by andyblem.)

I changed my second view a bit and its now submitting but I now have a new problem my deleteOffice function in my phones controller is not executing all of its instructions

Here is my new code
Code:
<div align="center">
<?php
$this->load->helper('form');
foreach($offices as $office)
{
     echo $office['names'];
     echo form_open('phones/deleteOffice');
      $data = array( 'name'        => 'office',
                     'value'       => $office['id']);
              
     echo form_submit('submit', 'Delete Ofiice');
     echo form_close();
}
?>
</div>
Reply
#5

(This post was last modified: 02-04-2015, 02:52 AM by InsiteFX.)

Is this Delete Office spelled correct?

PHP Code:
echo form_submit('submit''Delete Ofiice'); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

(02-04-2015, 02:51 AM)InsiteFX Wrote: Is this Delete Office spelled correct?


PHP Code:
echo form_submit('submit''Delete Ofiice'); 

It is not. I later corrected that mistake but it did not have any influence because it is the text that is displayed on the button
Reply
#7

(02-04-2015, 02:44 AM)andyblem Wrote: I changed my second view a bit and its now submitting but I now have a new problem my deleteOffice function in my phones controller is not executing all of its instructions

Here is my new code

Code:
<div align="center">
<?php
$this->load->helper('form');
foreach($offices as $office)
{
     echo $office['names'];
     echo form_open('phones/deleteOffice');
      $data = array( 'name'        => 'office',
                    'value'       => $office['id']);
              
     echo form_submit('submit', 'Delete Ofiice');
     echo form_close();
}
?>
</div>

1. Your form does not contain a field named 'office', so $this->input->post('office') in your controller is probably not going to give you an office to delete. One method of adding this data to the form would be to use echo form_hidden('office', $office['id']);.
2. The align attribute in your HTML was deprecated in 1999.
Reply
#8

(02-04-2015, 07:54 AM)mwhitney Wrote:
(02-04-2015, 02:44 AM)andyblem Wrote: I changed my second view a bit and its now submitting but I now have a new problem my deleteOffice function in my phones controller is not executing all of its instructions

Here is my new code


Code:
<div align="center">
<?php
$this->load->helper('form');
foreach($offices as $office)
{
echo $office['names'];
echo form_open('phones/deleteOffice');
 $data = array( 'name'        => 'office',
                    'value'       => $office['id']);
 
echo form_submit('submit', 'Delete Ofiice');
echo form_close();
}
?>
</div>

1. Your form does not contain a field named 'office', so $this->input->post('office') in your controller is probably not going to give you an office to delete. One method of adding this data to the form would be to use echo form_hidden('office', $office['id']);.
2. The align attribute in your HTML was deprecated in 1999.
Thank you man I had already found the solution but I think its proper to thank you. good job mate
Reply
#9

It's also a good idea to edit your post title and add [SOLVED] to the end of it.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB