1 Reply Latest reply on Apr 11, 2007 11:44 AM by MotionMaker

    passing variables to server is not working

      I am new to action scripts, so I'm not even sure where to start. I have bits and pieces that I know work, but am not sure why the action script and the php file on the server do not seem to be talking correctly to each other. The action script seems to work if I do not pass any variables, but only just a generic mail() function in the php file - i.e. mail("gen@someweb.com","Subject is photography","Mail message body is here."). If I try to use the variables passed from the action script, I get nothing :-(

      Here is the section of the action script and the php file that I am using currently (i have modified it many time and tried many things on the php side)

      //sends the data out
      bSend.onRelease = function() {
      var targetLoadVars:LoadVars = new LoadVars();
      var myLoadVars:LoadVars = new LoadVars();
      //sets form focus
      myLoadVars.emailFrom = c.text;
      myLoadVars.emailTo = "gen@someweb.com";
      myLoadVars.subject = "Photography Info";
      myLoadVars.name = a.text;
      myLoadVars.message = d.text;
      myLoadVars.sendAndLoad (" http://someweb.com/feedbck-1a.php", targetLoadVars, "POST");
      targetLoadVars.onLoad = function() {

      This is the feedbck-1.php file on the someweb.com server
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

      " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns=" http://www.w3.org/1999/xhtml">
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      // instantiate object
      $fv = new form_validator();

      name = targetLoadVars.name;
      emailFrom = targetLoadVars.emailFrom;
      message = targetLoadVars.message;
      emailTo = targetLoadVars.emailTo;

      if ($fv->validate_fields("name, emailFrom, message, emailTo"))
      mail($emailTo,"Photography inquiry",$message);
      // or list errors
      echo "The form could not be processed because the
      following fields contained invalid data:";
      echo "<ul>";
      foreach ($fv->error_array as $e)
      echo "<li>$e";
      echo "</ul>";
        • 1. Re: passing variables to server is not working
          MotionMaker Level 1
          Couple of thoughts

          1. The PHP side must only return (echo) standard MIME format application/x-www-form-urlencoded(a standard format used by CGI scripts).
          So you need to remove all the HTML and only have <?php at start and ?> at the end with no whitespace before or after these tags including tabs, enter keys and spaces.
          Inside you have echo return the URL encoded variables.

          2. Prove the PHP script outside of Flash by creating a standard HTML form that sends the values. This will allow you to see the return values from the PHP script that they are in the requisite encoded form and any PHP errors assuming you have the PHP error messages open.

          3. Place
          targetLoadVars.onLoad = function() {
          before the sendAndLoad.
          You are assigning a variable and it is remotely possible that the sendAndLoad fires the onLoad before the lines following it are processed. A remotely possible failure is not a good item to have in code.

          4. Also might be a variable scope problem:
          Define these outside of the onRelease function.
          var targetLoadVars:LoadVars;
          var myLoadVars:LoadVars;

          Inside the onRelease
          targetLoadVars = new LoadVars();
          myLoadVars = new LoadVars();