Welcome Guest, Not a member yet? Register   Sign In
Set the value of "set_value" in controller


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...orm_01.png

- The user can submit (Absenden) or preview (Vorschau) the mobile message:
- http://i387.photobucket.com/albums/oo317...orm_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

$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



There are a few ways to get this done:

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

// 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.


Hope this helps. Good luck!


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>'.

Theme © iAndrew 2016 - Forum software by © MyBB