Lesson 09: Writing to Data Files

This example uses the [[APPEND_FILE]] shortcode to store the form response in a data file called comments.txt located in the node’s root folder. Note that the \t creates a tab delimiter and the \n creates a new line in output string to be stored. To overwrite previous content use [[WRITE_FILE]] instead.

Create a node and paste this following code into it’s landing page editor.  Goto the node’s address and test with browser.

[[IF_SUBMITTED]]
 [[POST:Name]]
 [[POST:Message]]
 [[INITIALIZE:submitted_entry|"$Name\t$Message\t\n"]]
 [[INITIALIZE:filename|"comments.txt"]]
 [[APPEND_FILE:submitted_entry|filename]]
 Thank you [[PRINT:Name]] , your comment has been added to the file.[[cr]]
[[END_IF]]
Here is the comment form.[[cr]][[hr]]
[[FORM:#this]]
 [[INPUT:Name|Enter Your Name]]
 [[INPUT:Message|Enter Your Comment]]
 [[SUBMIT:Save]]
[[END_OF_FORM]]

Leave a Reply