Welcome Guest, Not a member yet? Register   Sign In
form validation for NOT matches
#1

[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?
#2

[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
#3

[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
#4

[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);
#5

[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',
#6

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

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

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

[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>
#10

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




Theme © iAndrew 2016 - Forum software by © MyBB