开发者

CodeIgniter Form Validaton + JS. Form re-population

开发者 https://www.devze.com 2022-12-28 07:32 出处:网络
I have a from with a checkbox, and depending on the checkbox state 2 different divs are shown. var alias = document.getElementById(\'alias\');

I have a from with a checkbox, and depending on the checkbox state 2 different divs are shown.

            var alias = document.getElementById('alias');
            var list = document.getElementById('list');
            if(document.getElementById('isList').checked)
            {
                alias.style.display = 'none';
                list.style.display = 'table-row';

            } else {
                alias.style.display = 'table-row';
                list.style.display = 'none';
            }

Here is the HTML/PHP (relevant) part:

<tr id="alias" style="display:table-row;">
      <td>' . form_label('Destination:', 'destination') . '</td>
      <td>' . form_textarea('destination') . '</td>
</tr>
<tr  id="list" style="display:none;">
     <td>' . form_label('File Path:', 'list_path') . '</td>
     <td>' . form_input('list_path') . '</td>
</tr>

alias div is shown by default on page load, list shown then i click on isList checkbox, and alias is shown again when i click on the checkbox again. This part 开发者_C百科works great and pretty straight froward.

Now, I add CodeIgniter Form Validation plugin, set appropriate rules and set-up validation plugin to re-populate the form with.

Without checkbox enabled everything works great. On errors form is re-populated.

However, when form is submitted with checkbox enabled, I have an issue. CI's Form Validation plugin re-populates the form, and re-enables the checkbox, but the list div that is supposed to be shown when checkbox enabled is not there, and instead the alias div is shown.

Is there any way around this issue? Can i have the list div shown on list validation error?

Also, i would like to avoid using JavaScript form validation, and stick with my good old PHP.

Thank you in advance. -i


Ha... I just fixed it with a simple

<body onload="showHide();">

0

精彩评论

暂无评论...
验证码 换一张
取 消