Form helper textarea load file |
Hi Guys,
Sorry, I am a beginner to codeigniter I am using textarea from "form helper" and I need to add some text to it. It's a big text so I want to put it in a different file and call this file on $data value variable how can I do it? Thanks
Hey... Well, I think the easiest way to do it, without having to open the file or create a handle or anything like that, is to use the get_file_contents() function.
PHP Code: $data = get_file_contents('text_for_textarea_field.txt');
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
(09-07-2015, 02:03 PM)Looks like this function doesn\t exist Wrote:
Looks like it is file_get_contents and not get_file_contents
Now I don't get any error. But it also doesn't work I am calling it directly, forgive my stupidity $data = array( 'name' => 'txt_area', 'id' => 'txt_area', 'value' => file_get_contents('resources/contract/contract.txt'), 'rows' => '18', 'cols' => '22', 'style' => 'width:50%', ); (09-07-2015, 03:50 PM)gabrielpasv Wrote: Looks like it is file_get_contents and not get_file_contents You should use htmlspecialchars to escape your external file contents. See http://php.net/manual/en/function.htmlspecialchars.php
Oops, so sorry to have misled you. I get that one confused a lot. Anyway, your code is fine. I tried it with a different file name. There's no problem calling the function the way you're calling it. However, the function is probably returning false because either the path or the file name are wrong.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
(09-07-2015, 05:55 PM)RobertSF Wrote: Oops, so sorry to have misled you. I get that one confused a lot. Anyway, your code is fine. I tried it with a different file name. There's no problem calling the function the way you're calling it. However, the function is probably returning false because either the path or the file name are wrong. The path is correct. Still not working ![]()
09-08-2015, 07:54 AM
(This post was last modified: 09-08-2015, 07:58 AM by ivantcholakov. Edit Reason: A clarification )
Test with an absolute path, for example: file_get_contents(APPPATH.'resources/contract/contract.txt')
PS: If you use CI2.x, check whether constants like FCPATH or APPPATH really represent absolute paths.
I was able to make it work now , thanks
![]() Hey, any chance you guys know how to make this textarea read-only ? So the user can't change it ? I am writing a "terms and conditions" agreement for a web commerce site Thanks (09-08-2015, 09:28 AM)gabrielpasv Wrote: I was able to make it work now , thanks Add readonly attribute to textarea tag. http://www.w3schools.com/tags/att_textarea_readonly.asp |
Welcome Guest, Not a member yet? Register Sign In |