Welcome Guest, Not a member yet? Register   Sign In
Form input fields +form_validation required but not equal to default???
#1

[eluser]123wesweat[/eluser]
Hi,

so i am using this to make some form fields
Code:
<?php echo form_label('fname').form_input('fname','fname');?>

and form_validation
Code:
$this->form_validation->set_rules('fname', 'fname', 'trim|required');

1/ Now because i already have fname as text value the validation passes, how do i fix this?
2/ How do is set already filled in values?? set_value???

regards,
#2

[eluser]123wesweat[/eluser]
Is this the way to do it for each input field?????
Code:
$fname = isset($_REQUEST['fname']) ? $_REQUEST['fname'] : 'fname';
$data = array(
              'name'        => 'fname',
              'id'          => 'fname',
              'value'       => $fname
            );

echo form_label('fname').form_input($data);
#3

[eluser]danmontgomery[/eluser]
Code:
<?php echo form_label('fname').form_input('fname',set_value('fname'));?>
#4

[eluser]123wesweat[/eluser]
@noctrum, thanks

But now we don't have a default value to start with?? Let's say "..here your first name"

Code:
<?php echo form_label('fname').form_input('fname','...here your first name'));?>
So that's why i think
Code:
$fname = isset($_REQUEST['fname']) ? $_REQUEST['fname'] : '...here your first name';
echo form_label('fname').form_input('fname',$fname));?

But now i have the validation question. As the validation 'thinks', ...here your first name is your name and it will validate.

Any thoughts??
#5

[eluser]jbreitweiser[/eluser]
Write a callback that tests for your default value and fails if that value is found.

Code:
function notDefaultText($str){
  if($str == '...here your first name'){
     return FALSE;
  } else {
     return TRUE;
  }
}
Now set your form validation to
Code:
$this->form_validation->set_rules('fname', 'fname', 'trim|required|callback_notDefaultText');




Theme © iAndrew 2016 - Forum software by © MyBB