Welcome Guest, Not a member yet? Register   Sign In
Form data preview - let user choose to submit or edit again
#1

[eluser]mjsilva[/eluser]
Hi igniters!

First post here, started today learning this beautiful framework, so let me just say as more I program with CodeIgniter more I like it.

I was working on a site with no php framework for a week, with just a few hours I've remade all site using CodeIgniter!! I'm impressed with speed of deving!

Thanks for all the develop and documentation, both are really awesome!!


Now for my first problem that required a post:

I have a controler with this function:
Code:
function AddClient(){


        $this->form_validation->set_rules('logo', 'Logo' , 'trim');
        $this->form_validation->set_rules('name', 'Nome' , 'trim|required|min_length[2]');
        $this->form_validation->set_rules('address', 'Morada' , 'trim|required|min_length[2]');
        $this->form_validation->set_rules('postalCode', 'Código Postal' , 'trim|required|exact_length[8]');
        $this->form_validation->set_rules('town_city', 'Cidade/Distrito' , 'trim|required|min_length[2]');
        $this->form_validation->set_rules('country', 'País' , 'trim|required');
        $this->form_validation->set_rules('generalContact', 'Contacto geral' , 'trim|required|numeric|exact_length[9]');
        $this->form_validation->set_rules('generalEmail', 'E-mail' , 'trim|required|valid_email');

        if ($this->form_validation->run() == FALSE){
            //Form Atributes
            $attributes = array('class' => 'addForm', 'id' => 'addClient');
            $formTag = form_open('clients/AddClient', $attributes);

            $data = array('formAction' => $formTag);

            $this->load->view('AddClient_form_view', $data);
        }else{
            
            $data['logo'] = $this->input->get_post('logo');
            $data['name'] = $this->input->get_post('name');
            $data['address'] = $this->input->get_post('address');
            $data['postalCode'] = $this->input->get_post('postalCode');
            $data['town_city'] = $this->input->get_post('town_city');
            $data['country'] = $this->input->get_post('country');
            $data['generalContact'] = $this->input->get_post('generalContact');
            $data['generalEmail'] = $this->input->get_post('generalEmail');
            
            $this->load->view('AddClient_verify_view', $data);
        }


every thing is working the problem is in AddClient_verify_view page:

Code:
<table class="verifyForm">
<tr><td>Nome:</td><td>&lt;?=$name?&gt;</td></tr>
<tr><td>Morada:</td><td>&lt;?=$address?&gt;</td></tr>
<tr><td>C&eacute;digo Postal:</td><td>&lt;?=$postalCode?&gt;</td></tr>
<tr><td>Cidade/Distrito:</td><td>&lt;?=$town_city?&gt;</td></tr>
<tr><td>Pa&iacute;s:</td><td>&lt;?=$country?&gt;</tb></tr>
<tr><td>Contacto geral:</td><td>&lt;?=$generalContact?&gt;</td></tr>
<tr><td>E-mail geral:</td><td>&lt;?=$generalEmail?&gt;</td></tr>
<tr><td align="center" colspan="2">&lt;input type="button" value="submit" /&gt;&lt;input type="button" value="back to edit" /></td></tr>
</table>

I don't how to pass values neither for a function to submit data to mysql DB or to get back to editing form.


Can someone pointing me to the right direction, what is the best technique to accomplish this?


TIA, cheers,

MJS
#2

[eluser]Johan André[/eluser]
If you want show the user a preview of what he entered in a form you should post it as usual, then "catch" the data into hidden inputs of a "invisible" form (use the same fieldnames as in your first form).

If the user clicks the save-button you save the data as normal.

I probably would validate the data before showing the preview and if the validation fails return to the first form and let the user correct it.
#3

[eluser]mjsilva[/eluser]
Tks Johan André,

Gonna try to put that in practice, brb with results.




Theme © iAndrew 2016 - Forum software by © MyBB