Below are the four required files to install a module that I created. They are all located within the '/third_party/database_add/' folder. My issue and my question is located after these files, which I am including to show what I've done so far.
File: database_add_lang.php
Location: /third_party/database_add/language/english/
$lang = array(
'my_module_module_name' => 'Database_add',
'my_module_module_description' => 'Contains functionality to add a user to the user table',
''=>''
);
File: mcp.database_add.php
Location: /third_party/database_add/
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Module_name_mcp {
}
/* End of file mcp.module_name.php */
/* Location: ./system/expressionengine/third_party/database_add/mcp.database_add.php */
File: mod.database_add.php
Location: /third_party/database_add/
class Database_add{
var $return_data = '';
function register(){
$username = "john"
$passhash = "smith"
$data = array(
'User_Name' =>$username,
'User_Passhash' =>$passhash
);
$query = ee()->db->insert('exp_user', $data);
}
function form(){
$return_data = ee()->functions->form_declaration(array(
'hidden_fields' => array(
'ACT' => ee()->functions->fetch_action_id('Database_add', 'register'),
),
));
$return_data .= ee()->TMPL->tagdata;
$return_data .= '</form>';
return $return_data;
}
}
File: upd.database_add.php
Location: /third_party/database_add/
class Database_add_upd{
var $version = '1.0';
function install(){
$data = array(
'module_name' => 'Database_add',
'module_version' => $this->version,
'has_cp_backend' => 'n',
'has_publish_fields'=> 'n'
);
ee()->db->insert('modules', $data);
$data = array(
'class' => 'Database_add',
'method' => 'add_user'
);
ee()->db->insert('actions', $data);
}
function uninstall(){
ee()->load->dbforge();
ee()->db->select('module_id');
$query = ee()->db->get_where('modules', array('module_name' => 'Database_add'));
ee()->db->where('module_id', $query->row('module_id'));
ee()->db->delete('module_member_groups');
ee()->db->where('module_name', 'Database_add');
ee()->db->delete('modules');
ee()->db->where('class', 'Database_add');
ee()->db->delete('actions');
return TRUE;
}
function update($current = ''){
return FALSE;
}
}
That is my file structure. I followed this EllisLab tutorial to get this far. My front-end form code looks like this:
{exp:database_add:form}
<input class="text_box" type="text" name="username" id="username" />
<input class="text_box" type="password" name="password" id="password" />
<input type="submit" name="submit_button" value="Register" />
{/exp:database_add:form}
The above form is simplified of course. The form successfully renders as this:
Now take a look at my register() function. No matter what I enter into the above form, I expect register() to fire, and the username "john" with the passhash "smith" to be entered into the "exp_user" table. That doesn't happen. The table remains empty. All that happens is my blank 'index.php' page loads.
My question is: How do I get the register() function to fire when I press the Submit button on the form?