I have some JavaScript libraries, files on my server, which I use in nuBuilder. My goal is to manage these external files by means of a form.
When I open a record, an external file should be loaded in a nuBuilder textarea field. When I save the record, the content of the textarea should be saved back to the JavaScript file.
Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Load/save file
-
- Posts: 785
- Joined: Sun Oct 14, 2018 11:25 am
Re: Load/save file
Hi,
This is how I implemented a tiny file editor.
Create a table with these fields:
file_id - type varchar(25) - primary key
file_name - type varchar(1000)
file_content - type text
Create a Browse/Edit Form with "Fast Forms". Fields field_name (input), file_content (textarea)
In your form's Custom Code (JS):
PHP (BE):
PHP (AS):
Whenever a record is saved, the content of file_content is saved to a file that is specified in the field file_name. When a record is opened, the file contents is loaded from the file too.
Hope that helps!
This is how I implemented a tiny file editor.
Create a table with these fields:
file_id - type varchar(25) - primary key
file_name - type varchar(1000)
file_content - type text
Create a Browse/Edit Form with "Fast Forms". Fields field_name (input), file_content (textarea)
In your form's Custom Code (JS):
Code: Select all
if (nuFormType() == 'edit') {
var c = atob(fileGetContents());
// instead of atob: use this class to properly decode: https://www.coditty.com/code/utf-base64-encode-in-php-and-decode-in-javascript
$('#file_content').val(c).change();
$('#file_content')
.dblclick(function() {
nuOpenAce('Javascript', this.id);
});
nuHasNotBeenEdited();
}
Code: Select all
$c = base64_encode(file_get_contents("#file_name#"));
$j = "
function fileGetContents(){
return '$c';
}
";
nuAddJavascript($j);
Code: Select all
$filename = "#file_name#";
if ($filename != '')
{
file_put_contents($filename,stripslashes("#file_content#"));
}
Hope that helps!
You do not have the required permissions to view the files attached to this post.