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>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();
?>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,
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
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.