Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] form_input attributes
#1

[eluser]Brandt1981[/eluser]
I've read the form helper user guide, but I still can't get it to work.


I have something like this in my view:

Code:
<?php echo form_open('home/query'); echo form_input('query', 'ID#'); echo form_close(); ?>

Which renders this:

Code:
<form action="https://mysite/home/query" method="post"><input type="text" name="query" value="ID#"  /></form>

I want to include javascript as it is a query box, I want there to be a default value of something like "Search", have the text be a gray color, and have the default value clear out on click, and then re-apper on blur. But I don't want the text that people to type it to be gray, I want that to be black.




Also for another form_input, I want it to be disabled if it's value contains text. If the value is blank, I want it enabled.
Code:
<?php echo form_input('empid',set_value('empid',$employee['pk_emp_id'])); ?>


I tried to do the thing from the user guide using $js in the form_input, and defining $js just above it in the view, but that didn't work an my page failed to render...I also tried defining $js in the controller and that didn't work either...sorry I'm a newbie

For the disabled part, I would like to do it without having to define an array somewhere if possible...

Thanks!!
#2

[eluser]bretticus[/eluser]
You are placing entirely too much emphasis on CodeIgniter where these things are mostly web layout or clientside functionality. That means stop looking at form helper, it's done all it needs to. Start looking into CSS and Javascript (just skip and go to jquery.)

EDIT: There is one item on your wish list (disable the input) that you can perform (although you might want to just do it with javascript Wink ) via the form helper.

The manual shows that you can send a single associative array for form_input and use any attribute you wish. Here's the example.

Code:
$data = array(
              'name'        => 'username',
              'id'          => 'username',
              'value'       => 'johndoe',
              'maxlength'   => '100',
              'size'        => '50',
              'style'       => 'width:50%',
            );

echo form_input($data);

// Would produce:

<input type="text" name="username" id="username" value="johndoe" maxlength="100" size="50" style="width:50%" />
#3

[eluser]Brandt1981[/eluser]
ack! I don't really know javascript!

If I can find an example of what I'm looking for and where to put it (view or controller?) then I would be able to implement it for sure!
#4

[eluser]Brandt1981[/eluser]
How do you get set_value to work with the array?

this is not working:

Code:
<?php $data = array(
                    'name'        => 'empid',
                    'value'       => 'set_value('empid',$employee['pk_emp_id'])',
                    'disabled'     => 'disabled',
                    );
    echo form_input($data); ?>
#5

[eluser]bretticus[/eluser]
[quote author="Brandt1981" date="1287463903"]I've read the form helper user guide, but I still can't get it to work.


I have something like this in my view:

Code:
<?php echo form_open('home/query'); echo form_input('query', 'ID#'); echo form_close(); ?>

Which renders this:

Code:
<form action="https://mysite/home/query" method="post"><input type="text" name="query" value="ID#"  /></form>

I want to include javascript as it is a query box, I want there to be a default value of something like "Search"[/quote]

There is a jquery plugin for this. I strongly suggest you learn CSS immediately. Knowing CSS better will not only help you with your layout (everyone uses CSS these days and it's unwise not to) it will help you use jquery because jquery "latches" on to HTML elements (no event attributes in your tags...besides, event attributes in HTML are so 2000-ish!)

[quote author="Brandt1981" date="1287463903"], have the text be a gray color,[/quote]

CSS!

[quote author="Brandt1981" date="1287463903"] and have the default value clear out on click, and then re-apper on blur. But I don't want the text that people to type it to be gray, I want that to be black.[/quote]
jquery and CSS. See the jquery plugin link above.
[quote author="Brandt1981" date="1287463903"]
Also for another form_input, I want it to be disabled if it's value contains text. If the value is blank, I want it enabled.[/quote]

Looks like you're on to this already using the form helper.
[quote author="Brandt1981" date="1287463903"]
Code:
<?php echo form_input('empid',set_value('empid',$employee['pk_emp_id'])); ?>


I tried to do the thing from the user guide using $js in the form_input, and defining $js just above it in the view, but that didn't work an my page failed to render...I also tried defining $js in the controller and that didn't work either...sorry I'm a newbie

For the disabled part, I would like to do it without having to define an array somewhere if possible...

Thanks!![/quote]

Resources:

Jquery for Absolute Beginners (excellent!)

CSS Tutorials
#6

[eluser]bretticus[/eluser]
[quote author="Brandt1981" date="1287481306"]How do you get set_value to work with the array?

this is not working:

Code:
<?php $data = array(
                    'name'        => 'empid',
                    'value'       => 'set_value('empid',$employee['pk_emp_id'])',
                    'disabled'     => 'disabled',
                    );
    echo form_input($data); ?>
[/quote]

Your PHP is wrong. You cannot really call a function (set_value) wrapped in quotes. It's a string in your example. It should be:

Code:
$data = array(
                    'name'        => 'empid',
                    'value'       => set_value('empid',$employee['pk_emp_id'])
                    );
if (!empty($employee['pk_emp_id']))
   $data['disabled'] = 'disabled';

    echo form_input($data);
#7

[eluser]Brandt1981[/eluser]
ugh...does disabling a text input prevent it's value from being submitted to the browser?

Suddenly my doctrine updates aren't working any more Sad


ah I just found this:

The boolean READONLY attribute, new in HTML 4.0, prevents the user from changing the input, but the input is still submitted with the form. The DISABLED attribute, also new in HTML 4.0, disables the control. Disabled elements are read-only elements with the added restrictions that the values are not submitted with the form, the elements cannot receive focus, and the elements are skipped when navigating the document by tabbing.


Luckily I learned HTML when it was 1.0 Tongue




Theme © iAndrew 2016 - Forum software by © MyBB