CodeIgniter Forums
Set the value of "set_value" in controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Set the value of "set_value" in controller (/thread-16284.html)



Set the value of "set_value" in controller - El Forum - 03-02-2009

[eluser]darytas[/eluser]
Hi,

first at all, I really enjoy CI.
I tried CakePHP and Zend, but they sucked compared to CI (bigger isnt alway better, right?).

So, I'm developing in a medium-sized company, currently on a project, related to mobile message service. Whatever, I stuck at the following problem:

(created some screenshots, but all of those are in german.)

- A user should enter some information (for a mobile message)
- http://i387.photobucket.com/albums/oo317/darytas/workish/smsform_01.png

- The user can submit (Absenden) or preview (Vorschau) the mobile message:
- http://i387.photobucket.com/albums/oo317/darytas/workish/smsform_02.png

So, my idea to create this form was the following:
- Submit the form and create an array
- Check if the preview button was clicked and decide with view to load

Code:
$smsdata = array ( 'senderid'   => $this->input->post('senderid'),
                   'recipients' => $this->input->post('recipients'),
                   'message'    => $this->input->post('message'),
                   '_date'      => $this->input->post('_date'),
                   '_hour'      => $this->input->post('_hour'),
                   '_minute'    => $this->input->post('_minute'),
                   'notify'     => $this->input->post('notify'),
                   'gateway'    => $this->input->post('gateway'));

            
           # preview or send sms
           if ($this->input->post(('preview'))) {

            # put data on view          
            $data['smsdata'] = $smsdata;
              
            # show preview
            $this->load->view('users/sms_preview', $data);
            
           } else {

            # send sms
            /* do real messsage sending here */

            # load sms sent view
            $this->load->view('users/sms_sent', $data);
            
           }


This stuff is working fine, but my problem is... how to get the values I got into the preview, back into the "editable form" if the user decides to edit the data currently available within the preview?

I hope my english is understandable! Wink

Thanks!

darytas


Set the value of "set_value" in controller - El Forum - 03-02-2009

[eluser]pilotLight_Tre[/eluser]
There are a few ways to get this done:

1) Store the array in a "flash" session. Example:

Code:
// set the session data
$this->session->set_flashdata('smsdata', $smsdata);
// get the data
$tmp_smsdata = $this->session->flashdata('smsdata');

2) Create a table to store temporarily "smsdata" values. Just delete the entries once the data has been published/finalized.

3) Use the Form Validation library. You have to load the library in order to use the set_value method. Just make sure you set the rules to all of the fields that you want the set_value method to display the temp. data even if the fields aren't required. Else, it'll display a blank field.

http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html

Hope this helps. Good luck!


Set the value of "set_value" in controller - El Forum - 03-02-2009

[eluser]darytas[/eluser]
Hi,

thanks, maybe I should have to define the question more in detail.

Is there a way, to set the value of the "set_value" of a specific field within the controller?

I got an array with 8 values (the one above) and want to associate i.e.:
$smsdata['message'] with '<input type="text" name="message" value="..." />'.

$smsdata['recipients'] can be an array which need to be associated to a '<select multiple>'.