We help IT Professionals succeed at work.

Mootools Javascript Autosave Form

hugooguh
hugooguh asked
on
613 Views
Last Modified: 2012-05-11
Hi,

I tried to get this class to work with no success:

https://github.com/arieh/Autosave

Need help please. I get a javascript object error in (demo.html) line 15

The local storage seems to work but not the database storage.

Comment
Watch Question

leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
You need top put the Source folder (which contains the Autosave.js script) same level as the Demo folder, not inside
OR if you put the Source folder inside the Demo folder modify line 13 & 14 like this :

<script type="text/javascript" src="Source/Autosave.js"></script>
    <script type="text/javascript" src="Source/Autosave.Request.js"></script>

Open in new window

Author

Commented:
Yes, the Source folder is at the same level. I uploaded all the files/folder as is on the server and create the “data” database using the sql file.

Is the “demo.html” working and saving to the database on your machine? (without a javascript error in debugging mode)

Thanks :)

autosave.gif
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Once I put the Source at the same level as the Demo folder the error line 15 left
You still get it?

For any others errors, did you create the table in a database and update the database login info in save.php?

Author

Commented:
Yes. same error (see image)

and the database connection is (save.php):

$pdo = new PDO('mysql:host=localhost;dbname=autosavetest','root','');


autosave2.gif
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
You did not include Autosave.Request.js

Author

Commented:
Thanks for your patience
I added the line :

<script type="text/javascript" src="../Source/Autosave.Request.js"></script>

So here is my demo.html source:

<!DOCTYPE HTML>
<html lang="en-US">
<head>
      <meta charset="UTF-8">
      <title>Autosave Demo</title>
</head>
<body>
    <h1>Autosave Demo</h1>
    <p>Enter some value into the textbox. That value will be autosaved every 5 seconds if changed. Even if you leave the page and open it again, The last data used will be saved.</p>
      <textarea name="exp1" id="exp1" cols="30" rows="10"></textarea>
    <a href="javascript:;" id='empty'>empty records</a>
    <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js'></script>
    <script type="text/javascript" src="../Source/Autosave.js"></script>
    <script type="text/javascript" src="../Source/Autosave.Request.js"></script>
    <script type="text/javascript">
        var as = new Autosave.Request('exp1','save.php','get.php',{emptyUrl : 'empty.php'});
     
        as.attach();
       
        $('empty').addEvent('click',function(){as.empty();});
    </script>
</body>
</html>

Code for the save.php:

<?php
$pdo = new PDO('mysql:host=localhost;dbname=myautosavetable','root','');
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$pdo->query("SET NAMES 'utf8'");

$value = $pdo->quote($_POST['value']);
$step = $pdo->quote($_POST['step']);
$id = $pdo->quote($_POST['id']);

$pdo->query("INSERT INTO `data`(`id`,`step`,`value`) VALUES ($id,$step,$value)");

Still have javascript error and do not save to table
autosave3.gif
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
update database login infos in save.php, empty.php and get.php

Author

Commented:
Yes, I have already done that.

This maybe a silly question to ask but…

In the save.php file, where do the:

$value = $pdo->quote($_POST['value']);
$step = $pdo->quote($_POST['step']);
$id = $pdo->quote($_POST['id']);

POSTS come from?

There is only one textarea in the demo.html form ie:
<textarea name="exp1" id="exp1" cols="30" rows="10"></textarea>

And the name is exp1.
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Did you create the table (run table.sql) ?
It run fine on my side.

>POSTS come from?
ajax call (Request.JSON) in the plugin

Author

Commented:
You mean the data.sql ? Yes. I created the table using

DROP TABLE IF EXISTS `data`;
CREATE TABLE `data` (
  `id` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
  `step` int(11) NOT NULL DEFAULT '0',
  `value` text COLLATE utf8_bin NOT NULL,
  PRIMARY KEY (`id`,`step`),
  FULLTEXT KEY `value` (`value`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

Did you include other files to make it run or just the ones included in the Autosave package? ie: Demo and Source folders.

Thanks again. First time I play with Mootools :(



Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Ok. I got the script to work on another server. I think, it was the mysql or PHP version that was the issue.

Thanks anyway :)
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
You're welcome! Thanks for the points! Have a nice week-end!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.