views:

300

answers:

3

Hi there, I was wondering if it's possible to store form data such as 'title' and 'description' in a javascript session?

I'm using the uploadify script to have a flash uploader, but the script isn't passing the title and description. This is my code at the moment;

<script type="text/javascript">

 jQuery(document).ready(function() {
  title = $("input#title").val();
  description = $("textarea#description").val();

  $('#uploadImage').uploadify({
   'uploader': 'flash/uploadify.swf',
   'script': 'process/process_uploaded_image.php',
   'folder': 'submitted/pictures',
   'cancelImg': 'images/cancel.png',
   'queueID'        : 'fileQueueImages',
   'auto'           : false,
   'multi'          : false,
   'fileExt' : '*.jpg;*.png;*.gif;*.jpeg;*.JPG',
   'fileDesc': 'Images ONLY (.jpg, .png, .gif, .jpeg, .JPG)',
   'buttonText' : 'BROWSE',
   'scriptData': {'title':title,'description':description,'user':'<?php echo $usr["id"] ?>'},
   'sizeLimit' : '2097152', //2MB
   //'buttonImg' : '/components/com_mm/assets/images/button-upload-images.png',
   //'width' : '218',
   //'height' : '66',
   onAllComplete: function() {
     //$('#uploadedImage').load(location.href+" #uploadedImages>*","");
     //location.reload(); //uncomment this line if youw ant to refresh the whole page instead of just the #allfiles div
     location.href = "upload-pics-thanks.php";
   },
   //onComplete: function(a, b, c, d, e){
   //     if (d !== '1')
   //           alert(d);
   //},
   onError: function (a, b, c, d) {
    alert("Error: "+d.type+"      Info: "+d.info);
   },
   onSelect: function () {

   } 
  });
 });
</script>
A: 

JavaScript does not have sessions. Probably the best way is to send your title&description via AJAX to the server.

Jan Hančič
A: 

Check out this SO answer and in case that doesn't work...

Did you see this post in the Uploadify forums? Maybe it'll point you in the right direction, and wow so much spam in those forums.

http://www.uploadify.com/forum/viewtopic.php?f=7&amp;t=3120

fudgey
A: 

If you use latest version of uploadify, the data in scriptData will be passed to script as either _POST or _GET (default is now POST) variable. So in your php file, you can get the title and description using:

$_POST['title']
$_POST['description']
$_POST['user']

Just consider it same with handling form submit, only it's originated from uploadify flash. Also note, the flash is not passing the current cookies that currently exist in the browser. If your php is using session stored in the cookies, it must be tweaked to read it from $_POST instead.

I use CodeIgniter, and there are patch for that in CodeIgniter forum. If you just use build in PHP session, you can pass the PHPSESSID inside scriptData, then in side script PHP, reinitialize session using passed data. It's have been answered in other question in stackoverflow, just search it with uploadify keyword.

Donny Kurnia