0

Here is what I am having trouble with, I am using HMVC and I have so far:

routes.php

$route['create_qso'] = 'qso/create_qso';
$route['insert_qso'] = 'qso/insert_qso';

Qso_model.php MODEL

function add_qso($data){

     $data = array(
        'user_id' => $this->input->post('user_id'),
        'date' => $this->input->post('date'),
        'time_in_field' => $this->input->post('time-in-field'),
        'discipline_id' => $this->input->post('discipline'),
        'shift_id' => $this->input->post('shift'),
        'type_id' => $this->input->post('type'),
        'at_risk_category_id' => $this->input->post('at-risk'),
        'at_risk_details' => $this->input->post('at-risk-details'),
        'severity_level_id' => $this->input->post('severity-level'));



    $this->db->insert('qso', $data);}

create_qso.php VIEW

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

// logic for form begins    
    $user_id_val = $this->session->userdata('user_id');
    $user_username_val = $this->session->userdata('username');

    //  discipline dropdown
    $disciplines = $this->db->query('SELECT DISTINCT discipline_desc FROM discipline');
    $disciplinedropdowns = $disciplines->result();
    foreach ($disciplinedropdowns as $disciplinedropdown){
        $disciplinedropdownlist[$disciplinedropdown->discipline_desc] = $disciplinedropdown->discipline_desc;
    }
    $finaldisciplinedropdown = $disciplinedropdownlist;

    // shift dropdown
    $shifts = $this->db->query('SELECT DISTINCT shift FROM shift');
    $shiftdropdowns = $shifts->result();
    foreach ($shiftdropdowns as $shiftdropdown){
        $shiftdropdownlist[$shiftdropdown->shift] = $shiftdropdown->shift;
    }
    $finalshiftdropdown = $shiftdropdownlist;

    // Type dropdown
    $types = $this->db->query('SELECT DISTINCT type FROM type');
    $typedropdowns = $types->result();
    foreach ($typedropdowns as $typedropdown){
        $typedropdownlist[$typedropdown->type] = $typedropdown->type;
    }
    $finaltypedropdown = $typedropdownlist;

    // At Risk dropdown
    $atriskcats = $this->db->query('SELECT DISTINCT at_risk_cat FROM at_risk_cat');
    $atriskcatdropdowns = $atriskcats->result();
    foreach ($atriskcatdropdowns as $atriskcatdropdown){
        $atriskcatdropdownlist[$atriskcatdropdown->at_risk_cat] =   $atriskcatdropdown->at_risk_cat;
    }
    $finalatriskdropdown = $atriskcatdropdownlist;

    // severity_level dropdown
    $severity_levels = $this->db->query('SELECT DISTINCT severity_level FROM severity_level');
    $severity_leveldropdowns = $severity_levels->result();
    foreach ($severity_leveldropdowns as $severity_leveldropdown){
        $severity_leveldropdownlist[$severity_leveldropdown->severity_level] = $severity_leveldropdown->severity_level;
    }
    $finalseverity_leveldropdown = $severity_leveldropdownlist;?>

<div class="text-left">
<h1 class="fg-primary f900 text-uppercase">Create QSO</h1>

</div>
<div id="add_qso_form">
<?php   echo form_open('create_qso/insert_qso');   
echo form_hidden('user_id', $user_id_val);  // hiding user id
$date = date("Y-m-d H:i:s");  // getting date in mySQL format
?>
<div class="col-sm-6">    
    <div class="form-group">  <!-- adding read only date -->
        <label for="date">Date</label>
        <?php 
        $datedata = array(
            'name'          => 'date',
            'id'            => 'date',
            'value'         => $date,
            'type'          => 'datetime',
            'class'         => 'form-control',
            'readonly'      =>  'true'
        );
        echo form_input($datedata); 
        ?>
    </div>
    <div class="form-group">   <!--Adding minutes observed-->
        <label for="time-in-field">Minutes Observed</label>
        <?php 
        $timeinfield = array(
            'name'          => 'time-in-field',
            'id'            => 'time-in-field',
            'value'         => '',
            'type'          => 'number',
            'min'           => '1',
            'max'           => '480',
            'class'         => 'form-control'
        );
        echo form_input($timeinfield); 
        ?>
    </div>
    <div class="form-group">   <!--Adding discipline-->
        <label for="discipline">Discipline</label>
        <?php
        $discipline_extras = array(
            'class' => 'form-control'
        );
        echo form_dropdown('discipline',$finaldisciplinedropdown,'',$discipline_extras); 
        ?>
    </div>
    <div class="form-group">   <!--Adding shift-->
        <label for="shift">Shift</label>
        <?php
        $shift_extras = array(
            'class' => 'form-control'
        );
        echo form_dropdown('shift',$finalshiftdropdown,'',$shift_extras); 
        ?>
    </div>
    <div class="form-group"> <!--Adding type-->
        <label for="type">Type</label>
        <?php
        $type_extras = array(
            'class' => 'form-control'
        );
        echo form_dropdown('type',$finaltypedropdown,'',$type_extras); 
        ?>

    </div>
</div>
<div class="col-sm-6">
    <div class="form-group"> <!--Adding At Risk Category-->
        <label for="type">At Risk Category</label>
        <?php
        $at_risk_cat_extras = array(
            'class' => 'form-control'
        );
        echo form_dropdown('at-risk',$finalatriskdropdown,'',$at_risk_cat_extras); 
        ?>

    </div>
    <div class="form-group">   <!--Adding At Risk Details-->
        <label for="time-in-field">At Risk Details</label>
        <?php 
        $timeinfield = array(
            'name'          => 'at-risk-details',
            'id'            => 'at-risk-details',
            'value'         => '',
            'type'          => 'text',
            'class'         => 'form-control'
        );
        echo form_textarea($timeinfield); 
        ?>
    </div>
    <div class="form-group"> <!--Adding severity_level-->
        <label for="severity_level">severity_level</label>
        <?php
        $severity_level_extras = array(
            'class' => 'form-control'
        );
        echo form_dropdown('severity-level',$finalseverity_leveldropdown,'',$severity_level_extras); ?>

    </div>

</div>
<div class="text-center">
<?php
    echo form_submit('submit', 'Submit QSO');
    echo form_open('create_qso/insert_qso');
?>

</div>

</div>

Create_qso.php CONTROLLER

class Create_qso extends Site_Controller 
{

public function __construct()
{
    parent::__construct();
    //Transfers data to model
    $this->load->model('Qso_model'); // load the model

} 

public function index() {  
    //  Quick Page setup is the same as $this->load->view() method used in CI
    $this->quick_page_setup(Settings_model::$db_config['active_theme'], 'main', 'Create QSO', 'create_qso', 'header', 'footer');  

    // Setting values for table coloums

}
public function insert_qso() {

    $this->Qso_model->add_qso();
    $this->load->view('qso/insert_qso');

}
}

When I run this, the form displays great and I can enter data, but when I submit the form I get this:

http://versumgas.com/error_images/form-error.jpg

I can't figure out how to get from the form to insert data into my qso table on my database?

2
  • I went through the codeigniter documentation and looks like I got it correct. I am going to try and go through the tutorail on a seperate local site, to see it if works... This should be much simplier than I am making it, but since I am new to codeigniter, then I have to expect a learning curve. :-( Commented Nov 4, 2016 at 20:40
  • No replies... :-( Commented Nov 5, 2016 at 13:44

1 Answer 1

1

What type of HMVC did you use?

First, this my HMVC folders: HMVC folder

I don't need to use $route['method'] to config url or view. I just use $this->load->view('account',$this->_data); in when I want to load view, and account.php will be place in application\modules\account\views

If it cannot connect and show error, maybe problem should be your HMVC source. I used HMVC at bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc for my project.

Second, In your VIEW file, is this correct? The form here is form_close, it's not form_open, right?

<div class="text-center">
<?php
    echo form_submit('submit', 'Submit QSO');
    echo form_open('create_qso/insert_qso');
?>
</div>

It should be:

<div class="text-center">
<?php
    echo form_submit('submit', 'Submit QSO');
    echo form_close('create_qso/insert_qso');
?>
</div>

I don't have enough reputation to comment your question. So please comment back, I'll check and reply to you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.