0

I want to write a javascript string into a file called preview.html in my server. I am trying to use the Get method to pass the javascript string to php but it doesn't seem to be working. I am using aloha editor and the javascript string Result contains the content entered by the user.

This is a simple version of my work which is not working, any idea why?:

<script type="text/javascript">
    // make the div editable by user
    Aloha.ready(function() {
            $('#title').aloha();
    });
    // When submit is clicked
    function onSubmit() {
            var e = Aloha.getEditableById('title');
            var Result = e.getContents();
            location.href="page.php?Result=" + Result;
             }
</script>
<div id="title">Title. Click to Edit.</div>
<a href="javascript:onSubmit();">Submit</a>
 <?php
    $fp = fopen('preview.html', 'w');
    $r = $_GET['Result'];
    fwrite($fp, $r); 
    fclose($fp);?>
Aust
  • 11,552
  • 13
  • 44
  • 74
Jiyda Moussa
  • 925
  • 2
  • 9
  • 26
  • Just out of curiousity, what are you trying to accomplish? – James McDonnell Nov 29 '12 at 23:53
  • I have multiple aloha editable divs that form a proof template. After editing the content of each div, the user should have the ability to preview the whole proof. Hence, I am trying to combine the content of all the editables in one string and writing this string into a file called preview.html. I would have a button at the end that the user can click on and it would redirect him to that page. – Jiyda Moussa Nov 30 '12 at 01:05
  • This would be much easier accomplished with the session or posting in a form to a page. – James McDonnell Nov 30 '12 at 01:07

1 Answers1

0

You could use an ajax request to store the editable content. Here is a simple example with Aloha Editor: https://gist.github.com/1448270 This will save the data of multiple editables to a SQLite DB (from there it will be inserted into html)

There is an other demo app which saves the data to a file: https://github.com/alohaeditor/Aloha-Editor/blob/dev/src/demo/demo-app/app/save-to-file.php

rene.kapusta
  • 136
  • 1