Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

How to retrieve hidden form variables

Help
Rob
2007-02-21
2013-05-30
  • Rob
    Rob
    2007-02-21

    Hi,

    I have a page produces dynamic hidden variables for a form post.

    I need to be able to submit those same variables to the form. How can I use Snoopy to do this?

    Example:

    1. Log into site

    $submit_vars['user'] = 'user';
    $submit_vars['pwd'] = 'pwd';
    $submit_vars['submit'] = 'submit';

    $submit_url = "http://www.mysite.com/login.php";
    if (!$snoopy->submit($submit_url,$submit_vars)) {
        die ("error fetching document: ".$snoopy->error."\n");
    }

    2. Go to form page (with dynamic hidden variables)

    $snoopy->setcookies();
    $url = 'http://www.mysite.com/form.php';

    if (!$snoopy->fetch($url)) {
        die ("error fetching document: ".$snoopy->error."\n");
    }

    3. Submit to form (but with dynamic hidden variables)

    $submit_vars['??'] = '??'; //can I set the hidden form variable here somehow?

    $snoopy->setcookies();
    $submit_url = 'http://www.mysite.com/post.php';
    if (!$snoopy->submit($submit_url,$submit_vars)) {
        die("error fetching document: ".$snoopy->error."\n");       
    }

    Thanks,
    Rob.

     
    • sharp
      sharp
      2007-02-21

      The only 2 things that snoopy can give you are:
      1) HTTP Headers

      Example:

      POST /mcmd/events HTTP/1.1
      Host: wwwl.meebo.com
      User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
      Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
      Accept-Language: en-us,en;q=0.5
      Accept-Encoding: gzip,deflate
      Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
      Keep-Alive: 300
      Connection: keep-alive
      Content-Type: application/x-www-form-urlencoded
      Referer: http://wwwl.meebo.com/index-en.html
      Content-Length: 87
      Pragma: no-cache
      Cache-Control: no-cache
      sessionKey=a816c3ffa72123db3c12e5de716bba444f9e33754c3ab1ba5511b0ab&rev=30&focusTime=18
      =======================================================================

      2) Page content
      Example:
      well, you know ... the content of the page you`ve requested (either by post(aka: submit) or get(aka: fetch))
      =================================================
      In other words, no.. you cannot see the hidden fields of a form by using something like: $snoopy->form["formName"]->field["fieldName"];
      But, you can do a fetch on the form you wish to submit ... manually parse the content for any hidden fields (gather from this parsing whatever you wish) and then setup your snoopy and submit! :) ... hope this helps! cheers ;)

      btw, I have a friend which goes by the name of spaceboy... any chance you`re from Romania? :)

       
    • Rob
      Rob
      2007-02-21

      Thanks for the help. I'm thinking I'll have to go with option #2, and parse the form contents.

      Thanks again,
      Rob.

      p.s. Sorry, not the same person, as I'm from Canada :)