Welcome Guest, Not a member yet? Register   Sign In
Validating a Form - How to set values on Dropdown Boxes?
#1

[eluser]Sinclair[/eluser]
Hi,

I'am validating a form and I need to set_value on a <select>. I'am able to set the value, but I need also to show the text that is different from the value set.

The code is:
Code:
<p>
          <label for="name">G&eacute;nero: </label>
        <select name="genero">
        <option></option>
        &lt;?php foreach ($generos as $rowgeneros): ?&gt;
        <option value="&lt;?php echo set_value('genero', $rowgeneros->id_genero); ?&gt;">&lt;?php echo $rowgeneros->n_genero; ?&gt;</option>
        &lt;?php endforeach; ?&gt;
        </select>
      </p>

Wich is the best option to show the value selected on "echo $rowgeneros->n_genero;"

Best Regards,
#2

[eluser]pistolPete[/eluser]
Have a look at the form helper's method set_select(): http://ellislab.com/codeigniter/user-gui...elper.html
#3

[eluser]Sinclair[/eluser]
It is working now.

Thanks a lot!

Best Regards.
#4

[eluser]Sinclair[/eluser]
I have another doubt...

It is possible to have Callbacks with more thab 1 parameter?

The problem is that I have 3 select boxes for input the date of birth, and I need to validade if the user don't input 31 of february, for example.

I have userd the checkdate function, something like this:

Code:
function veracidade_check($vMES, $vDIA, $vANO){
        $valor = checkdate($vMES, $vDIA, $vANO);
        if ($valor == '1')
            {
                
                return true;
            }        
            else
            {
                $this->form_validation->set_message('anodatanascimento_check', 'O %s tem de estar preenchido.');
                return false;
            }
    }

It is possible to use callback function with more than 1 parameter? If not, how can I validate the inputs of 3 select boxes?


Best Regards,
#5

[eluser]pistolPete[/eluser]
How about that:

Code:
function your_callback()
{
     $day = $this->input->post('day');
     $month = $this->input->post('month');
    
     if($month == 2 && $day > 30)
     {
          return FALSE;
     }
    
     return TRUE;
}
#6

[eluser]Sinclair[/eluser]
Great!

It is working now. I have used the checkdate function. For example if I input 29 February of 1982 give me false.

Code:
$valor = checkdate($this->input->post('month'),
                   $this->input->post('day'),
           $this->input->post('year'));




Theme © iAndrew 2016 - Forum software by © MyBB