Welcome, Guest
  • Author Topic: passing toString() to a PHP file  (Read 1661 times)

    jiffyloop

    • Server what's that
    • *
    • Posts: 22
    • Flash-db Rules
      • View Profile
      • Email
    passing toString() to a PHP file
    « on: 09/20/02, 11:41 »
    I'm not sure how to go about what I'm trying to do here, but I'll try to explain as brief as possible. I have a form in flash in which you'll be able to name your own field names and variables. I have created a LoadVars object. I have all the variables dumped together using toString() which brings me something like this:

    credit=this%20is%20new%20credits&source=%3CU%3E%3Cb%3Ethis%20is%20a%20new%20source%3C%2FB%3E%3C%2FU%3E&moviename=hiking&headline=this%20is%20my%20new%20content%20system&fieldCount=4

    jiffyloop

    • Server what's that
    • *
    • Posts: 22
    • Flash-db Rules
      • View Profile
      • Email
    OOPS!! All my text didn't copy over!!
    « Reply #1 on: 09/20/02, 11:46 »
    I'm not sure how to go about what I'm trying to do here, but I'll try to explain as brief as possible. I have a form in flash in which you'll be able to name your own field names and variables. I have created a LoadVars object. I have all the variables dumped together using toString() which brings me something like this:

    credit=this%20is%20new%20credits&source=%3CU%3E%3Cb%3Ethis%20is%20a%20new%20source%3C%2FB%3E%3C%2FU%3E&moviename=hiking&headline=this%20is%20my%20new%20content%20system&fieldCount=4

    Now I want to be able to pass this over to a PHP script which will then write this to a text file. I'm a PHP beginner and I'm familiar with some simple scripts to write to a text file. But thats only if I know the variable names already. But if the variable names will be different, how do I go about that??

    Any help would be appreciated!!

    Thanks,

    Jiffy Loop

    Musicman

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 2685
      • View Profile
      • Email
    Re:passing toString() to a PHP file
    « Reply #2 on: 09/20/02, 16:12 »
    Hi,

    the loadvrs object should just send its vars to a php script with the POST method.
    The php script should contain a list of expected variables

    Musicman

    jiffyloop

    • Server what's that
    • *
    • Posts: 22
    • Flash-db Rules
      • View Profile
      • Email
    Re:passing toString() to a PHP file
    « Reply #3 on: 09/20/02, 16:33 »
    well I found one solution that seemed to work.

    in Flash I just set a variable to equal my toString()

    flashVariable = formData.toString()

    then in PHP, I just created another variable

    $newVariable = $flashVariable

    There might be more efficient andf better ways to approach this, but this was the only way I could come up with. Musicman, if you could post some code that you think might help my situation, that would be great. I'm still unsure about what you said about "The php script should contain a list of expected variables". How do you call those or pull those up??

    Jiffy Loop

    Musicman

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 2685
      • View Profile
      • Email
    Re:passing toString() to a PHP file
    « Reply #4 on: 09/20/02, 16:51 »
    Code: [Select]

    $varnames = array("ucredit","source","moviename",...)
    foreach($varnames as $v)
    {         if(isset($_POST[$v]))
                   $data[] = "$v=" . urlencode($v);
    }
    $newdata = implode("&", $data);


    Musicman

    jiffyloop

    • Server what's that
    • *
    • Posts: 22
    • Flash-db Rules
      • View Profile
      • Email
    Re:passing toString() to a PHP file
    « Reply #5 on: 09/20/02, 17:06 »
    thanks for the code Musicman...but my only problem is that the variable names will change and I'd like it to be more dynamic...I don't want to hardcode the variables in.

    Musicman

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 2685
      • View Profile
      • Email
    Re:passing toString() to a PHP file
    « Reply #6 on: 09/20/02, 17:26 »
    Hi,

    the hardcoded names are meant to protecrt you from idiots sending rubbish to your script.
    A script that takesall post vars would be
    Code: [Select]

    foreach($_POST  as $v)
            $data[] = "$v=" . urlencode($_POST[$v]);
    $newdata = implode("&", $data);


    Musicman