Avatar of hugooguh
hugooguh
 asked on

Mootools Javascript Autosave Form

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.

AJAXJavaScript

Avatar of undefined
Last Comment
leakim971

8/22/2022 - Mon
leakim971

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

hugooguh

ASKER
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
leakim971

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?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
hugooguh

ASKER
Yes. same error (see image)

and the database connection is (save.php):

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


autosave2.gif
leakim971

You did not include Autosave.Request.js
hugooguh

ASKER
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
leakim971

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

ASKER
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.
leakim971

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

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

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
hugooguh

ASKER
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 :(



ASKER CERTIFIED SOLUTION
leakim971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
hugooguh

ASKER
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 :)
leakim971

You're welcome! Thanks for the points! Have a nice week-end!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.