Welcome Guest, Not a member yet? Register   Sign In
set_select, multiple items, re-populating :(
#1

[eluser]darytas[/eluser]
hey,

right now i'm very confused (again) by codeigniter.

Code:
<select name="smsform[phonebook][]" id="phonebook-list" class="field select large" size="6" multiple="multiple">

&lt;?php foreach($phonebooks as $phonebook) : ?&gt;
            
<optgroup label="&lt;?=$phonebook['name']?&gt;">
  
   &lt;?php foreach($entries as $entry)
           if ($entry['pid'] == $index) :
   ?&gt;

   <option value="&lt;?= $entry['number']?&gt;" &lt;?= set_select('smsform[phonebook][]', $entry['number'])?&gt;>&lt;?= $entry['name']?&gt; (&lt;?= $entry['number']?&gt;)</option>

  &lt;?php endif; ?&gt;                                            

</optgroup>

&lt;?php endforeach; ?&gt;

</select>

i really don't get why the form isn't repopulated.
tried several things yet, $this->form_validation->set_value, with and without [].

any ideas?

maybe i'm just stupiid and don't see the error.


thanks in advance,

darytas
#2

[eluser]jedd[/eluser]
[quote author="darytas" date="1246626178"]

Code:
<select name="smsform[phonebook][]" id="phonebook-list" class="field select large" size="6" multiple="multiple">
[/quote]

Should there be some dollar signs in there somewhere or do you believe square brackets come through that kind of gauntlet unscathed (actually - do they? I've never tried - it looks dangerous)


And rather than this:
Quote:
Code:
<select name="smsform[phonebook][]" id="phonebook-list" class="field select large" size="6" multiple="multiple">

&lt;?php foreach($phonebooks as $phonebook) : ?&gt;
            
<optgroup label="&lt;?=$phonebook['name']?&gt;">
  
   &lt;?php foreach($entries as $entry)
           if ($entry['pid'] == $index) :
   ?&gt;

   <option value="&lt;?= $entry['number']?&gt;" &lt;?= set_select('smsform[phonebook][]', $entry['number'])?&gt;>&lt;?= $entry['name']?&gt; (&lt;?= $entry['number']?&gt;)</option>

  &lt;?php endif; ?&gt;                                            

</optgroup>

&lt;?php endforeach; ?&gt;

</select>

Have you considered committing to PHP and doing something like this instead?
Code:
&lt;?php
    echo "<select name=\"". $smsform['phonebook'][] ."\" id=\"phonebook-list\" class=\"field select large\" size=\"6\" multiple=\"multiple\">\n";
    foreach ($phonebooks as $phonebook)  {
        echo "<optgroup label=\"". $phonebook['name'] ."\">\n";
        foreach ($entries as $entry)  {
            if ($entry['pid'] == $index)  {
                echo "<option value=\"". $entry['number'] ."\"". set_select('smsform[phonebook][]', $entry['number']) .">";
                echo $entry['name'] ."(". $entry['number'] .")";
                echo "</option>\n";
                }
            }
        echo "</optgroup>\n";
        }
    echo "</select>\n";

Sure, you may be the person that finds the constant &lt;?= ?&gt; easy on the eye, but I can't but help think that one of the reasons you're confused by your own code is lines like this!
Code:
<option value="&lt;?= $entry['number']?&gt;" &lt;?= set_select('smsform[phonebook][]', $entry['number'])?&gt;>&lt;?= $entry['name']?&gt; (&lt;?= $entry['number']?&gt;)</option>
#3

[eluser]Mirage[/eluser]
Hi,

I don't know if your issue was resolved, but at least as of 1.7.1, you pre-populating fields MUST be defined in the form_validation config, even if they don't require validation. If they are not defined, you'll get blanks.

Personally, I kinda consider this a flaw and un-necessary. If it's not defined just gimme the dang $_POST value. Please?

-m




Theme © iAndrew 2016 - Forum software by © MyBB