Trying to make a "save as" form using php's "file_put_contents" and javascript... "Filename cannot be empty"
<p>I'm trying to make a "save as" feature using javascript and php.  In the html I use: </p>

<pre><code>&lt;textarea id="filename" cols="20" rows="1"&gt;&lt;/textarea&gt;    
&lt;li class ="add" onclick="js:saveas()" &gt;save&lt;/li&gt;
</code></pre>

<p>Then with inline javascript I do this to get the filename and dynamically generated dom:</p>

<pre><code>&lt;script&gt;
function saveas() {
   $.post('write.php', { name : $('#filename').val() });
   $.post('write.php', { dom : $('html').html() });
    }

 &lt;/script&gt;
</code></pre>

<p>Then over in "write.php"...</p>

<pre><code>&lt;?php
$name = urldecode($_POST['name']);
$dom = urldecode($_POST['dom']);
file_put_contents($name, $dom);

?&gt;
</code></pre>

<p>But the console says:</p>

<pre><code>[30-Aug-2012 15:45:22] PHP Notice:  Undefined index: dom in /Users/J/Documents/test7/test7/write.php on line 3

[30-Aug-2012 15:45:22] PHP Notice:  Undefined index: name in /Users/J/Documents/test7/test7/write.php on line 2

[30-Aug-2012 15:45:22] PHP Warning:  file_put_contents() [&lt;a href='function.file-put-contents'&gt;function.file-put-contents&lt;/a&gt;]: Filename cannot be empty in /Users/J/Documents/test7/test7/write.php on line 4
</code></pre>

<p>And it creates the file with the correct name but it's empty, zero bytes.  However if I hardcode the filename, like this:</p>

<pre><code>file_put_contents('foo.html', $dom);
</code></pre>

<p>everything works the way it should, though I still get the notices.  Any ideas on what I'm doing wrong?</p>
