reading values from a form

Help
zentac
2007-05-23
2013-05-30
  • zentac
    zentac
    2007-05-23

    Ive got the following

    $mainpage->fetchform($submit_url);

    This give me the form within $mainpage->results;

    <form method="post" action="page1a.html" onsubmit="return CheckForOther();">
    <input type="hidden" name="cart" value="117986392526367">
    <select name="test" class="select">
    <option value="error">Select from list...

    I need to pull the cart value out of $mainpage->results how do I do that?

     
    • sharp
      sharp
      2007-05-23

      Well, it`s not what you think ... $snoopy->form[0]->field[x] ... etc :)

      You simply have the $snoopy->content which containts the full returned html page. You parse this page, and extract what you like ...

      Not familiar with the word parse? Well then, you keep chopping the string down until you remain with what you need ... for example

      <form method="post" action="page1a.html" onsubmit="return CheckForOther();">
      <input type="hidden" name="cart" value="117986392526367">
      <select name="test" class="select">
      <option value="error">Select from list...

      $pos_start = stripos($content,"name=\&quot;cart\&quot; value=\&quot;")+strlen("name=\&quot;cart\&quot; value=\&quot;"); (1)
      $content   = substr($content,$pos_start); (2)
      $pos_end   = stripos($content,"\&quot;>"); (3)
      $content   = substr($content,0,$pos_end); (4)

      (1) --> gives you the position of (name="cart" value=") ==> but we need the position of (117986392526367) so .. we add the length of the string (name="cart" value=")
      (2) --> $content should now be:
      117986392526367">
      <select name="test" class="select">
      <option value="error">Select from list...
      (3) --> gives you the position of (">)
      (4) --> $content should now be "117986392526367" (there might had been errors on my code .. so try to understand the idea, search the functions, see what they do .. and use them)

      Good luck!

       
    • zentac
      zentac
      2007-05-23

      Thanks for that, the final solution was

              $mainpage->fetchform($submit_url);

              $pos_start = strpos($mainpage->results,"name=\&quot;cart\&quot; value=\&quot;")+strlen("name=\&quot;cart\&quot; value=\&quot;");
              $CART = substr($mainpage->results,$pos_start);
              $pos_end = strpos($CART,"\&quot;>");
              $CART = substr($CART,0,$pos_end);