CodeIgniter Forums
form validation for NOT matches - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: form validation for NOT matches (/showthread.php?tid=26649)

Pages: 1 2


form validation for NOT matches - El Forum - 01-19-2010

[eluser]blorriman[/eluser]
I have a form and I am using the following to create an input:
echo form_input('first_name', set_value('first_name', 'enter first name'));

I then validate the form:
$this->form_validation->set_rules('first_name', 'Name', 'trim|required');

However, because the form opens with "enter first name" in the text input, the required validation doesn't work.

I like the look this way instead of adding a label, but how do I validate this as required now?


form validation for NOT matches - El Forum - 01-19-2010

[eluser]JHackamack[/eluser]
There are one of two options.

You can use placeholder='Enter First Name'
which looks similar, but has a default value of ""

Or do a client side validation on submit that the form doesn't contain "enter first name" in the first name field


form validation for NOT matches - El Forum - 01-19-2010

[eluser]blorriman[/eluser]
Thanks JHackaMack,
I tried :
$name = 'enter name';
echo form_input('first_name', set_value('first_name', $name));

but it's still not validating


form validation for NOT matches - El Forum - 01-19-2010

[eluser]JHackamack[/eluser]
Try This
Code:
$data = array(
              'name'        => 'first_name',
              'id'          => 'first_name',
              'placeholder' => 'First Name',
              'value'       => set_value('first_name','set first name')
            );

echo form_input($data);



form validation for NOT matches - El Forum - 01-19-2010

[eluser]blorriman[/eluser]
Still no luck - it is picking up "set first name" from:
'value' => set_value('first_name','set first name')
'placeholder' => 'First Name',


form validation for NOT matches - El Forum - 01-19-2010

[eluser]JHackamack[/eluser]
Ah, sorry. Ignore the ",'set first name'" in the value field and try that.


form validation for NOT matches - El Forum - 01-19-2010

[eluser]blorriman[/eluser]
then the input is empty


form validation for NOT matches - El Forum - 01-19-2010

[eluser]JHackamack[/eluser]
Can you copy the generated HTML into here?


form validation for NOT matches - El Forum - 01-19-2010

[eluser]blorriman[/eluser]
Code:
<div id="signup_form" class="span-10">
    <fieldset>
        <legend>Create New Account</legend>
    &lt;?php
        echo form_open('login/create_member');
        $data = array(
              'name'        => 'first_name',
              'id'          => 'first_name',
              'placeholder' => 'First Name',
              'value'       => set_value('first_name','set first name')
            );

        echo form_input($data). '<br>';
//        echo form_input('first_name', set_value('first_name', 'enter first name')). '<br>';
        echo form_input('last_name', set_value('last_name', 'last name')). '<br>';
        echo form_input('email_address', set_value('email_address', 'email address')). '<br>';
    ?&gt;
    </fieldset>
</div>
<div id="signup_form" class="span-10 push-2">
    <fieldset>
        <legend>Login Information</legend>
        &lt;?php
            echo form_input('username', set_value('username', 'username')). '<br>';
            echo form_input('password', set_value('password','password')). '<br>';
            echo form_input('password2', set_value('password2','confirm password')). '<br>';
            echo form_submit('submit', 'create account'). '<br>';
        ?&gt;

        &lt;?= validation_errors('<p class="error">');?&gt;
    </fieldset>
</div>



form validation for NOT matches - El Forum - 01-19-2010

[eluser]JHackamack[/eluser]
Im looking for how it outputs in your browser.