We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Problems getting forms to post in CP admin

Development and Programming

matrixgroup's avatar
matrixgroup
15 posts
13 years ago
matrixgroup's avatar matrixgroup

I am developing a module with a couple admin pages. On one of these pages I have a form which I am having trouble getting to submit. The form is accessed from /admin.php?S=e682591a4e763e2ad6233b57637e1c5a273c871d&D=cp&C=addons_modules&M=show_module_cp&module=webinar_applications and should be submitting back to itself. The page loads fine when I navigate to it but when the form is submitted I get redirected back to the control panel home page ( /admin.php ). Is there something special I need to do to make Expression Engine recognize the form post?

<form action="<?php echo BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=webinar_applications'; ?>" method="post">
<div>
    <label for="f_name">First Name</label><input type="text" id="f_name" name="f_name" value="">
    <label for="l_name">Last Name</label><input type="text" id="l_name" name="l_name" value=""><br>
   </div>
<input type="submit" name="submit" value="Search" class="submit" id="search_button">
</form>
       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
13 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

Hi Matrixgroup,

You should redirect like :

$this->EE->functions->redirect(BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=webinar_applications');

in the function where you are posting data.

hope it would help you.

Best Regards,

       
matrixgroup's avatar
matrixgroup
15 posts
13 years ago
matrixgroup's avatar matrixgroup

The problem is that the code isn’t even getting to the function I desire. EE redirects to the main page before my plugin code is even executed.

the code in my mcp file looks like

<?php
define( 'APPLICATIONS_MODULE_INDEX', BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=applications' );

class Applications_mcp {
 public $applications = array();
 
 function __construct()
 {
  $this->EE =& get_instance();
 }
 
 function index()
 {
  //die();
  $this->EE->load->library( 'table' );
  $this->EE->load->library( 'javascript' );
  
  $this->EE->jquery->plugin( BASE.AMP.'C=javascript'.AMP.'M=load'.AMP.'plugin=tablesorter', TRUE) ;
  $this->EE->jquery->tablesorter( '.mainTable', '{headers: {6: {sorter: false}, 7: {sorter: false}, 8: {sorter: false}}, widgets: ["zebra"]}' );
  
  $this->EE->cp->set_variable( 'cp_page_title', $this->EE->lang->line( 'applications_module_name' ));
  
  $this->EE->javascript->compile();
  
  
  $vars = array(
    'applications' => $this->_get_applications( $this->EE->input->get_post() ) );
  
  return $this->EE->load->view( 'index', $vars, TRUE );
 }

 private function _get_applications( $args = array() )
 {
  //code to query the database
  return $database_query->result()

 }
}

My view file looks like this:

<?php  
$cp_table_template['table_open']);
?>
<div id="filerMenu">
 <fieldset>
  <legend>Search Applications</legend>
  <form action="<?php echo APPLICATIONS_MODULE_INDEX; ?>" method="GET">
   <div>
    <label for="f_name">First Name</label><input type="text" id="f_name" name="f_name" value="">
    <label for="l_name">Last Name</label><input type="text" id="l_name" name="l_name" value=""><br>
   </div>
   <div class="group">
    <br><select name="status">
     <option value="">Filter by application status</option>
     <option value="all">Any</option>
     <option value="approved">Approved</option
     <option value="declined">Declined</option>
    </select>
    <input type="submit" name="submit" value="Search" class="submit" id="search_button">
   </div>
  </form>
 </fieldset>
</div>
<br>
<?php
 $this->table->set_template($cp_table_template);
 $this->table->set_heading(
  lang('f_name'),
  lang('l_name'),
  lang('org'),
  lang('email'),
  ''
 );
 
 foreach( $applications as $application )
 {
  $this->table->add_row(
   $application->f_name,
   $application->l_name,
   $application->org,
   $application->email
   '<input type="checkbox" name="toggle[]" class="toggle">' );
 }
 
 echo $this->table->generate();
?>
       
Bhashkar Yadav's avatar
Bhashkar Yadav
727 posts
13 years ago
Bhashkar Yadav's avatar Bhashkar Yadav

Hi Matrixgroup,

You need to pass method name into form action of view file. I think, you would like to post form data into the index method. But this method wouldn’t be called on submission.

$vars['action'] = BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=applications'.AMP.'method=save_applications';

use this action as form action.

also you should create another method save_applications where you should process post data and st end of that method use redirect.

$this->EE->functions->redirect(BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=webinar_applications');

Hope this would help you.

Best Regards,

       
the3mus1can's avatar
the3mus1can
426 posts
13 years ago
the3mus1can's avatar the3mus1can

You need to use the form_open helper. Check out the form example in the docs: http://ellislab.com/expressionengine/user-guide/development/module_tutorial.html

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.