samedi 11 juin 2016

Second Bootstap Modal ajax result to show in first modal

I want to display form 2 data (which is a bootstrap modal) to show in form 1 (which is also a bootstrap modal) When i save form 2 data it save in db but reload page but i want to display with in form 1. First question is, am i trying something impossible?

Form 1 and + sign to open send modal

enter image description here

Second form

enter image description here Here is form 2 code

<div class="modal-dialog modal-lg">
<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-2x">&times;</i>
        </button>
        <h4 class="modal-title" id="myModalLabel"><?php echo lang('add_customer'); ?></h4>
    </div>
    <?php $attrib = array('data-toggle' => 'validator', 'role' => 'form', 'id' => 'add-customer-form');
    echo form_open_multipart("customers/add", $attrib); ?>
    <div class="modal-body">
        <p><?= lang('enter_info'); ?></p>
        <div class="form-group">
            <label class="control-label"
                   for="customer_group"><?php echo $this->lang->line("default_customer_group"); ?></label>
            <div class="controls"> <?php
                foreach ($customer_groups as $customer_group) {
                    $cgs[$customer_group->id] = $customer_group->name;
                }
                echo form_dropdown('customer_group', $cgs, $this->Settings->customer_group, 'class="form-control tip select" id="customer_group" style="width:100%;" required="required"');
                ?>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group company">
                    <?= lang("company", "company"); ?>
                    <?php echo form_input('company', '', 'class="form-control tip" id="company" data-bv-notempty="true"'); ?>
                </div>
                <div class="form-group person">
                    <?= lang("name", "name"); ?>
                    <?php echo form_input('name', '', 'class="form-control tip" id="name" data-bv-notempty="true"'); ?>
                </div>
                <div class="form-group">
                    <?= lang("vat_no", "vat_no"); ?>
                    <?php echo form_input('vat_no', '', 'class="form-control" id="vat_no"'); ?>
                </div>
                <!--<div class="form-group company">
                <?= lang("contact_person", "contact_person"); ?>
                <?php echo form_input('contact_person', '', 'class="form-control" id="contact_person" data-bv-notempty="true"'); ?>
            </div>-->
                <div class="form-group">
                    <?= lang("email_address", "email_address"); ?>
                    <input type="email" name="email" class="form-control" required="required" id="email_address"/>
                </div>
                <div class="form-group">
                    <?= lang("phone", "phone"); ?>
                    <input type="tel" name="phone" class="form-control" required="required" id="phone"/>
                </div>
                <div class="form-group">
                    <?= lang("address", "address"); ?>
                    <?php echo form_input('address', '', 'class="form-control" id="address" required="required"'); ?>
                </div>
                <div class="form-group">
                    <?= lang("city", "city"); ?>
                    <?php echo form_input('city', '', 'class="form-control" id="city" required="required"'); ?>
                </div>
                <div class="form-group">
                    <?= lang("state", "state"); ?>
                    <?php echo form_input('state', '', 'class="form-control" id="state"'); ?>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <?= lang("postal_code", "postal_code"); ?>
                    <?php echo form_input('postal_code', '', 'class="form-control" id="postal_code"'); ?>
                </div>
                <div class="form-group">
                    <?= lang("country", "country"); ?>
                    <?php echo form_input('country', '', 'class="form-control" id="country"'); ?>
                </div>
                <div class="form-group">
                    <?= lang("ccf1", "cf1"); ?>
                    <?php echo form_input('cf1', '', 'class="form-control" id="cf1"'); ?>
                </div>
                <div class="form-group">
                    <?= lang("ccf2", "cf2"); ?>
                    <?php echo form_input('cf2', '', 'class="form-control" id="cf2"'); ?>
                </div>
                <div class="form-group">
                    <?= lang("ccf3", "cf3"); ?>
                    <?php echo form_input('cf3', '', 'class="form-control" id="cf3"'); ?>
                </div>
                <div class="form-group">
                    <?= lang("ccf4", "cf4"); ?>
                    <?php echo form_input('cf4', '', 'class="form-control" id="cf4"'); ?>
                </div>
                <div class="form-group">
                    <?= lang("ccf5", "cf5"); ?>
                    <?php echo form_input('cf5', '', 'class="form-control" id="cf5"'); ?>
                </div>
                <div class="form-group">
                    <?= lang("ccf6", "cf6"); ?>
                    <?php echo form_input('cf6', '', 'class="form-control" id="cf6"'); ?>
                </div>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <?php echo form_submit('add_customer', lang('add_customer'), 'class="btn btn-primary"'); ?>
    </div>
</div>
<?php echo form_close(); ?>

Where as here is controller function

function add()
{
    $this->sma->checkPermissions(false, true);
    $this->form_validation->set_rules('email', lang("email_address"), 'is_unique[companies.email]');
    if ($this->form_validation->run('companies/add') == true) {
        $cg = $this->site->getCustomerGroupByID($this->input->post('customer_group'));
        $data = array('name' => $this->input->post('name'),
            'email' => $this->input->post('email'),
            'group_id' => '3',
            'group_name' => 'customer',
            'customer_group_id' => $this->input->post('customer_group'),
            'customer_group_name' => $cg->name,
            'company' => $this->input->post('company'),
            'address' => $this->input->post('address'),
            'vat_no' => $this->input->post('vat_no'),
            'city' => $this->input->post('city'),
            'state' => $this->input->post('state'),
            'postal_code' => $this->input->post('postal_code'),
            'country' => $this->input->post('country'),
            'phone' => $this->input->post('phone'),
            'cf1' => $this->input->post('cf1'),
            'cf2' => $this->input->post('cf2'),
            'cf3' => $this->input->post('cf3'),
            'cf4' => $this->input->post('cf4'),
            'cf5' => $this->input->post('cf5'),
            'cf6' => $this->input->post('cf6'),
        );
    } elseif ($this->input->post('add_customer')) {
        $this->session->set_flashdata('error', validation_errors());
        redirect('customers');
    }
    if ($this->form_validation->run() == true && $cid = $this->companies_model->addCompany($data)) {
        $this->session->set_flashdata('message', lang("customer_added"));
        $ref = isset($_SERVER["HTTP_REFERER"]) ? explode('?', $_SERVER["HTTP_REFERER"]) : NULL;
        redirect($ref[0] . '?customer=' . $cid);
    } else {
        $this->data['error'] = (validation_errors() ? validation_errors() : $this->session->flashdata('error'));
        $this->data['modal_js'] = $this->site->modal_js();
        $this->data['customer_groups'] = $this->companies_model->getAllCustomerGroups();
        $this->load->view($this->theme . 'customers/add', $this->data);
    }

Aucun commentaire:

Enregistrer un commentaire