Welcome Guest, Not a member yet? Register   Sign In
Repopulating Form being displayed through Jquery UI tabs interface
#1

[eluser]Timothy_[/eluser]
Hello,

I have a form at /booking/edit/ that is being displayed via iframe through a Jquery UI tab at /booking/view#edit.

The form submits to /booking/edit_process/

I am using the Codeigniter Form Validation Library.

Unfortunately I am having problems repopulating the form in the event of a validation failure.

I can't use set_value() or set_select() as I am using a redirect to go back to my edit tab /booking/view#edit and these variables seem to be getting lost.

I have read that using flashdata is an option for these kinds of scenarios however when I attempt to send the form variables back I can only echo them from the parent /booking/view/ not the original form at /booking/edit/.

I appreciate all thoughts and suggestions!!!!
#2

[eluser]Timothy_[/eluser]
Come on people. There has to be some way to achieve this. I am pretty desperate and all options (if I knew of them) are on the table.

At the moment when people edit the form within the tab and they trigger a validation failure all that post data is lost.

I really need a way to save all that post data as its being processed by the edit_process function. Then I need to somehow send the edit function that data so I can repopulate all the fields as I am rendering that view. Sounds easy but I have tried and tried and cannot get this data through the jquery tabs barrier... even though its only client side...

I guess I was hoping someone had done this before.
#3

[eluser]Basketcasesoftware[/eluser]
I'd like to help. I'm interested in using that JQuery feature myself in the installer of my main project. But right now I see from your end is some mention of some functions and snippets of paths. Are you comfortable with actually sharing the code? If not in this public forum maybe to myself in PM or email? I can do a non-disclosure agreement if it helps.
#4

[eluser]Timothy_[/eluser]
Hello,

The code is nothing special or out of the ordinary.

Here is a simplified controller I quickly put together:

Code:
function edit()
{
    //get values for the form from the database
    $this->db->select('id, name, street, suburb, state')->from('myusers')->where('id', $user_id);
    $data['get_values'] = $this->db->get();
    
    //then pack them up here
    $this->load->vars($data);
    
    //now load the view
    $this->load->view('edit_form');

}


function edit_process()
{

    $this->load->library('form_validation');
    $this->form_validation->set_rules('id', 'id', 'required');
    $this->form_validation->set_rules('name', 'name', 'required');
    $this->form_validation->set_rules('street', 'street');
    $this->form_validation->set_rules('suburb', 'suburb');
    $this->form_validation->set_rules('state', 'state');

    if ($this->form_validation->run() == FALSE)
    {
    
    $errors = validation_errors();
    $this->session->set_flashdata('message', $errors);
    redirect('user/edit');
    
    } else {
    
    //Insert Data here.
    
    }

}

And my view file for the edit form
Code:
<?php if($get_values->result_array()) { ?>
    <?php foreach($get_values->result_array() as $row): ?>
    
    <?php echo form_open('user/edit_process/'); ?>

    <input type="hidden" name="id" value="<?php echo set_value('id', $row['id']; ?>" />

    <input type="text" name="name" value="<?php echo set_value('name', $row['name']); ?>" />

    <input type="text" name="street" value="<?php echo set_value('street', $row['street']); ?>" />

    <input type="text" name="suburb" value="<?php echo set_value('suburb', $row['suburb']); ?>" />

    <input type="text" name="state" value="<?php echo set_value('state', $row['state']); ?>" />

    </form>
    
    <?php endforeach; ?>
<?php } ?>

And my view file for the page that loads the edit form into the tabs
Code:
[removed]
function() {
    $('#tabs').tabs();
}
[removed]
<?php echo $this->session->flashdata('message');?>
<div id="tabs">
<ul>
    <li><a href="/">Home</li>
    <li><a href="/user/edit">Edit</a></li>
</ul>
</div>


As you can see there is nothing to exotic about the code. The problem is getting these post values back to the edit function in the user controller.

Hope someone can help.

Tim
#5

[eluser]Basketcasesoftware[/eluser]
Cool. I see something already that looks a little strange to me.
Code:
$this->load->vars($data);
$this->load->view('edit_form');
Why are you using vars like that instead of just passing $data directly to the view?
e.g.
Code:
$this->load->view('edit_form',$data);
#6

[eluser]Timothy_[/eluser]
Ah yes, I suppose its because I use the template library and all my other calls for loading data have to be called in this way out of habit.

Code:
$this->load->vars($data);
$this->template->write_view('something', 'some/location');
$this->template->render();

I have changed it to the method you outlined above but I don't think this will make a difference.

This make sense as there is no problem with the initial loading of the data. Just bringing the post data back.
#7

[eluser]Basketcasesoftware[/eluser]
Which template library are you using that demands that? Odd. Ok.

Hmm. You load the flash data with an error message. Then do a redirect back to the edit form...

... but don't look for flash data in your edit form. Nor do you store the form data into your flash for recovery purposes. When you redirect to the page the form data is lost.

Unless you dropped that stuff out of your simplified example.
#8

[eluser]Timothy_[/eluser]
Yes, well this is where the fun begins.

I have tried a few different methods of setting the post data to flash data.

The first problem is simply converting the post data to flash data. I have no idea how to do this.
The second problem I have found is that the flash data is not going to the edit form view, but rather it is going view file with the jquery tabs. This is what we need to solve.

You can see in my view file that I am loading the error message coming from edit_process using

Code:
&lt;?php echo $this->session->flashdata('message');?&gt;

This works and thats precisely the point. I don't want the flash data to be displayed here, I want the flash data to be displayed at the form level.

Does this make any sense?

PS I am using this template library (http://williamsconcepts.com/ci/codeignit...rence.html) and i highly recommend it.
#9

[eluser]Basketcasesoftware[/eluser]
Ok. I see that in the last view but I didn't see you doing anything in your edit method in your controller.

Reading up on the CI form validation class...
Interesting comment in pink in the CI 2.0 user guide. You are using 2.0 aren't you?
Quote:Note: The form fields are not yet being re-populated with the data when there is an error. We'll get to that shortly.
#10

[eluser]InsiteFX[/eluser]
When you use:
Code:
$this->load->vars($data);
It makes all the variables global to all views.

So if you have a view that loads other views the variables will be available to the other views.
If you just pass $data to a view with other views in it, the other views will not see the variables.

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB