CodeIgniter Forums
Form helper textarea load file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 2.x (https://forum.codeigniter.com/forumdisplay.php?fid=18)
+--- Thread: Form helper textarea load file (/showthread.php?tid=62913)



Form helper textarea load file - gabrielpasv - 09-07-2015

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


RE: Form helper textarea load file - RobertSF - 09-07-2015

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'); 



RE: Form helper textarea load file - gabrielpasv - 09-07-2015

(09-07-2015, 02:03 PM)Looks like this function doesn\t exist Wrote:
Code:
PHP Fatal error:  Call to undefined function get_file_contents()



Code:
root@ubuntu64:/# php --version
PHP 5.5.9-1ubuntu4.11 (cli) (built: Jul  2 2015 15:23:08)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
   with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
root@ubuntu64:/#




RobertSFHey... 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'); 



RE: Form helper textarea load file - gabrielpasv - 09-07-2015

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%',
);


RE: Form helper textarea load file - pdthinh - 09-07-2015

(09-07-2015, 03:50 PM)gabrielpasv 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%',
               );

You should use htmlspecialchars to escape your external file contents.
See http://php.net/manual/en/function.htmlspecialchars.php


RE: Form helper textarea load file - RobertSF - 09-07-2015

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.


RE: Form helper textarea load file - gabrielpasv - 09-08-2015

(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

Sad


RE: Form helper textarea load file - ivantcholakov - 09-08-2015

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.


RE: Form helper textarea load file - gabrielpasv - 09-08-2015

I was able to make it work now , thanks Smile

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


RE: Form helper textarea load file - pdthinh - 09-08-2015

(09-08-2015, 09:28 AM)gabrielpasv Wrote: I was able to make it work now , thanks Smile

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

Add readonly attribute to textarea tag.
http://www.w3schools.com/tags/att_textarea_readonly.asp