Welcome Guest, Not a member yet? Register   Sign In
form_helper - bug or unwanted feature?
#1

[eluser]Bogdan Tanase[/eluser]
Hi,

First of all, i'd like to tell you that i love CI. I discovered it about one month ago... and i'm in love Big Grin

However i bumped into the following issue:

Some of the form_helper functions (like form_input, form_textarea) echoes a newline (\n) after the html input tag. This behaviour can create problems if you try to include a form_input function into a javascript string, for example, because it breaks the string.

Code:
< script >

  js_string='Some html here <span> &lt;?=form_input("test_input")?&gt; </span> the rest of the html here';

< / script >
The js code above is broken because form_input function appends newline (\n) after the input tag, thus breaking the string.

I solved my problem by editing the form_helper class and removing the newlines...
#2

[eluser]xwero[/eluser]
I'm not that found of adding the newline but the Ellislab developers think it's important to create a readable html source.

You given me the match to rekindle the fire Wink
#3

[eluser]richthegeek[/eluser]
maybe have a form helper setting?

Code:
form_append_newline( false );

It sets a global var, the newline's are no longer added, problem solved...
#4

[eluser]Derek Allard[/eluser]
Hm. Good point. What are your thoughts (and yours xwero) on the newlines in <select> and <option>. With input, textarea, etc, a dev could add them in as needed, but some controls like select (dropdown) wouldn't give them a way to do this.

Purty source code... I'm a sucker for it.
#5

[eluser]Derek Jones[/eluser]
Same here, I'd take readable source code over putting markup in Javascript any day. It frankly doesn't belong there, but extending this helper to get rid of the newlines is certainly an easy option for you if you disagree.
#6

[eluser]xwero[/eluser]
Adding a new line to form elements that are used inline most of the time makes the source code a bit awkward.
Code:
<p>&lt;?php echo form_label('What is your Name', 'username').form_input($data) ?&gt;</p>
// produces
<p><label for="username">What is your Name</label>&lt;input type="text" name="username" id="username" value="johndoe" maxlength="100" size="50" style="width:50%" /&gt;
</p>
I would rather see the p end tag on the same line like it is in the viewfile.

I have no problem with container tags and the select/option functions having a new line because i would place them on new lines too.

A bit off topic but i think if you really would like readable source code there would be an indentation parameter for all mark up creating functions and methods Wink
#7

[eluser]Bogdan Tanase[/eluser]
Well, i think php_penguin's suggestion (by setting some sort of parameter to activate/deactivate "pretty source code") might be a nice solution.

But in the end, it's not really an issue. If the developers think that their way is the best, it's quite easy for us to extend/modify the source code as we please.

Thanks for listening and sharing your thoughts.
#8

[eluser]Derek Allard[/eluser]
Quote:If the developers think that their way is the best..

I assure you we aren't that arrogant Wink

There's never a "best" way, but what we want is for CodeIgniter to be the most useful possible tool. It should be there to make your life easier, not more of a pain. Let us discuss this internally and see if we can't find a good solution for everyone. Then either Jones or I will drop back here to run it by you all, and if we're all on the same page, drop it into the core.
#9

[eluser]m4rw3r[/eluser]
I guess he meant users, like us here on the forum.

You are not the only developers Tongue
#10

[eluser]Bogdan Tanase[/eluser]
You might have misunderstood me. I didn't want to insinuate that any of you are arrogant or anything like that.

My English is not too good (it's not my native tongue), so i'm sorry if I accidentaly offended anyone.

The funny thing is that after i finished most of my js, my code became kinda messy (apparently Mr. Jones was right after all Smile ); and since i don't like messy code, eventually i ended up rewriting it from scratch: no more weird mixture of html/js/php, therefore, my initial problem is solved.

However, i still think that the newline should be more of a default option, rather than a mandatory one.




Theme © iAndrew 2016 - Forum software by © MyBB