trouble keeping radio button set

I am having some trouble setting keeping RADIO BUTTON checked.

Normally without CI I did it:

    <input  name="type" value="1" checked="checked"  type="radio" onChange="this.form.submit();"/>

    Offer

    <?php 
   if( !empty($_SESSION['type']) && $_SESSION['type'] == 2 )

       {

           echo "<input type=\"radio\" name=\"type\" value=\"2\"

           checked = \"checked\" onChange=\"this.form.submit();\" />";

           }else{

           echo "<input type=\"radio\" name=\"type\" value=\"2\" 

           onChange\"this.form.submit();\" 

           />";
   }     
    ?>
   Search

And then I use a condition:

    if(!empty($_SESSION['type']) && $_SESSION['type'] == 1)

    {

     dosomthing()

    }

I gave it a try, and I am getting two problems.

1- I'm using Onchange method to refresh the page, but it actually sending the form. (This didn't happen when I wasn't using CI)

2- When I select Search radio it doesn't stay there, it goes back to first radio.

This is what I did.

      <?php echo form_radio('type', '1', TRUE, 'onChange="this.form.submit();"'); ?>

      Offer

      <?php

      if( $this->session->userdata('type') && $this->session->userdata('type') == 2 )

       {

        echo form_radio('type', '2', TRUE, 'onChange="this.form.submit();"');

       }else{

        echo form_radio('type', '2', FALSE, 'onChange="this.form.submit();"');

       }

       ?>

       Search

      <?php

      if(($this->session->userdata('type')) && $this->session->userdata('type') == 1) 

       {

       dosomething();

       }
      ?>

Answers


Try this, You may need to change session value in your controller or model like this:

if($this->input->post("type") && $this->input->post("type")==2){
 $this->session->set_userdata('type', 2);
}
else{
 $this->session->set_userdata('type', 1);
}

Inside View:

<?php

      if( $this->session->userdata('type') && $this->session->userdata('type') == 2 )

       {

        echo form_radio('type', '2', TRUE, 'onchange="this.form.submit();"');

       }else{

        echo form_radio('type', '2', FALSE, 'onchange="this.form.submit();"');

       }

       ?>

       Search

      <?php

      if(($this->session->userdata('type')) && $this->session->userdata('type') == 1) 

       {

       dosomething();

       }
      ?>

Need Your Help

Keeping a numpy ndarray subclass as the return value during a transformation. Safe to set __array_priority__?

python arrays numpy subclass

I'm trying to subclass numpy's ndarray class, and have had some luck. The behavior that I would like is nearly exactly the same as the example given in the documentation. I want to add a parameter ...

C++: How to design a utility class?

c++ utilities code-design

But I don't know if I should go for static methods, just a header, a class, or something else?