Welcome Guest, Not a member yet? Register   Sign In
Form helper textarea load file
#1

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
Reply
#2

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!
Reply
#3

(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'); 
Reply
#4

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

(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
Reply
#6

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!
Reply
#7

(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
Reply
#8

(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.
Reply
#9

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

(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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB