CodeIgniter Forums

Full Version: Partial Views?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi is it possible to have an index list with a form submission created from partials?

For example I want to have a waitlist table shown with data populated from database, but there is also a modal with a form inside it to submit a new entry to the waitlist

PHP Code:
   public function index()
       $data['title'] = 'Home';

       $data['reservations'] = $this->Reservation_Model->get_reservation();


   public function create2()

       $data['title'] = 'Create a reservation';

       $this->form_validation->set_rules('name''Party Name''trim|required');
       $this->form_validation->set_rules('datetime''Date & Time''required');
       $this->form_validation->set_rules('partysize''Party Size''required');
       $this->form_validation->set_rules('phonenumber''Phone Number''required|exact_length[10]');

       if ($this->form_validation->run() === FALSE)

PHP Code:
<?php $this->load->view('reservation/create2'); ?>
<table class="shadow">
        <tr class="white">
            <th class="bg-blue">Reservation Time</th>
            <th class="bg-blue">Party Name</th>
            <th class="bg-blue">Party Size</th>
            <th class="bg-blue">Phone Number</th>
            <th class="bg-blue">Date Created</th>
    <?php foreach ($reservations as $reservation_item): ?>
            <td><?php echo $reservation_item['Datetime'?></td>
            <td><?php echo $reservation_item['Name'?></td>
            <td><?php echo $reservation_item['PartySize'?></td>
            <td><?php echo preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/""($1) $2-$3"$reservation_item['PhoneNumber']) ?></td>
            <td><?php echo $reservation_item['DateCreated'?></td>
    <?php endforeach ?>

PHP Code:
<? echo modal('modal-1''
<div class="form-container shadow">

    <h2>Create a reservation<small>Inputs</small></h2>

.group('Party Name''name''text'true).'

.group('Date & Time''datetime''datetime-local'true).'

.group('Party Size''partysize''number'true).'

.group('Phone Number''phonenumber''text'true).'

    <button type="submit" class="btn btn-raised btn-default pull-right">Create Reservation</button>

<button class="md-trigger" data-modal="modal-1">Popup Reservation Form</button> 

Currently I get error with validation_error and form_open not found. Anyway to make this work?
It will probably work if you load the form helper and form_validation library in the controller's constructor instead of loading them inside the create2 method. Since you don't call the create2 method until you submit the form in your modal, the helper and library aren't loaded and the functions aren't available.