form tags?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yang Li Ke

    form tags?

    Hi
    I know that there is a meta tag function to get all meta tags from a url.
    I am searching for a similar function that would get all values of a form.

    something like :

    <form>
    <input type="text" name="name" size="10">
    <input type="text" name="url" size="40">
    </form>

    it would return 'name', 'url'...

    Anyone can help?

    Yang


  • Daniel Tryba

    #2
    Re: form tags?

    Yang Li Ke <yanglike@sympa tico.ca> wrote:[color=blue]
    > <form>
    > <input type="text" name="name" size="10">
    > <input type="text" name="url" size="40">
    > </form>
    >
    > it would return 'name', 'url'...[/color]

    Take a look at the arays _GET, _POST (or even _REQUEST). The index of
    the array contain the names of the form.

    --

    Daniel Tryba

    Comment

    • Chung Leong

      #3
      Re: form tags?

      Nope. What you can use is preg_match_all to find the names.

      preg_match_all( '/<input.*?name\\ s*=\\s*"?([^\\s>"]*)/i', $text, $matches,
      PREG_PATTERN_OR DER);
      $names = $matches[1];

      Uzytkownik "Yang Li Ke" <yanglike@sympa tico.ca> napisal w wiadomosci
      news:2wFLb.1093 94$BA6.2183398@ news20.bellglob al.com...[color=blue]
      > Hi
      > I know that there is a meta tag function to get all meta tags from a url.
      > I am searching for a similar function that would get all values of a form.
      >
      > something like :
      >
      > <form>
      > <input type="text" name="name" size="10">
      > <input type="text" name="url" size="40">
      > </form>
      >
      > it would return 'name', 'url'...
      >
      > Anyone can help?
      >
      > Yang
      >
      >[/color]


      Comment

      • Pedro Graca

        #4
        [code] Re: form tags?

        Chung Leong wrote:[color=blue]
        > Yang Li Ke wrote:[color=green]
        >> I know that there is a meta tag function to get all meta tags from a url.
        >> I am searching for a similar function that would get all values of a form.[/color]
        > Nope. What you can use is preg_match_all to find the names.
        >
        > preg_match_all( '/<input.*?name\\ s*=\\s*"?([^\\s>"]*)/i', $text, $matches, PREG_PATTERN_OR DER);
        > $names = $matches[1];[/color]

        This has been a fun dive into regexps :-)

        I just *love* PHP arrays!



        I run this from the shell prompt
        pedro$ ./forminputs.php http://www.ebay.com/
        ___UNNAMED_FORM ___0:
        type=[hidden] name=[cgiurl] value=[http://cgi.ebay.com/ws/]
        type=[hidden] name=[krd] value=[1]
        type=[hidden] name=[from] value=[R8]
        type=[hidden] name=[MfcISAPICommand] value=[GetResult]
        type=[hidden] name=[ht] value=[1]
        type=[hidden] name=[SortProperty] value=[MetaEndSort]
        type=[text] name=[query] size=[25] maxlength=[300]
        type=[submit] value=[Search] class=[buttonsm]

        ___UNNAMED_FORM ___1:
        type=[submit] value=[Go] class=[buttonsm]

        ___UNNAMED_FORM ___2:
        type=[submit] value=[Go] class=[buttonsm]

        popout:
        type=[hidden] name=[popupurl] value=[http://pages.ebay.com/merchpopup/sell2all_A.html]



        code follows

        forminputs.php
        #v+

        #!/usr/bin/php4
        <?php
        require_once 'forminputs.inc .php';

        $x = get_form_inputs ($argv[1]);

        foreach ($x as $form_name=>$co ntents) {
        echo $form_name, ":\n ";
        foreach ($contents as $inputs) {
        foreach ($inputs as $k=>$v) if ($v) echo " $k=[$v]";
        echo "\n ";
        }
        echo "\n";
        }
        ?>

        #v-

        and now forminputs.inc. php, with the function
        #v+

        <?php
        function get_form_inputs ($file_url) {
        $retval = array(); // array that will be returned with the <input>s
        $attrs = array('type', 'name', 'value', 'checked', 'disabled', 'readonly',
        'size', 'maxlength', 'src', 'alt', 'usemap', 'ismap',
        'tabindex', 'accesskey', 'accept', 'id', 'class');
        $form_count = 0; // used later to generate unique names
        $html = file_get_conten ts($file_url);

        // forms cannot have forms inside
        preg_match_all( '@(<form\s.*</form>)@isU', $html, $forms);
        foreach ($forms[1] as $form) {

        // get the form name into $form_name, initialize with a unique name
        $form_name = '___UNNAMED_FOR M___' . $form_count++;
        if (!preg_match('@ <form[^>]+\sname="([^"]+)"@i', $form, $names)) {
        preg_match('@<f orm[^>]+\sname=(\w+)@i ', $form, $names);
        }
        if (isset($names[1]) && $names[1] != '') $form_name = $names[1];

        // get the <input>s
        preg_match_all( '@(<input\s[^>]*>)@iU', $form, $inputs);
        foreach ($inputs[1] as $input) {

        // get the three important input attributes
        foreach ($attrs as $a) {
        // should make an array with all the attributes and use it in a
        // loop
        $v[$a] = false; ## default value
        if ($a == 'type') $v[$a]='text'; ## default value
        if (!preg_match('@ <input[^>]*\s'.$a.'="([^"]+)"@i', $input, $values)) {
        preg_match('@<i nput[^>]*\s'.$a.'=(\w+) @i', $input, $values);
        }
        if (isset($values[1]) && $values[1] != '') $v[$a] = $values[1];
        }

        // add the <input>s to a new element of the return variable
        $retval[$form_name][] = $v;
        }

        // no select? no textarea? no button? no label?
        // no! :)

        }
        return $retval;
        }
        ?>

        #v-
        --
        --= my mail box only accepts =--
        --= Content-Type: text/plain =--
        --= Size below 10001 bytes =--

        Comment

        • Yang Li Ke

          #5
          Re: [code] Re: form tags?

          Hi Pedro,

          Thank you very much for that function but Im getting an error with the
          function undefined file_get_conten ts.

          Can you tell me why?

          Yang

          --


          "Pedro Graca" <hexkid@hotpop. com> wrote in message
          news:btnvk0$931 8s$1@ID-203069.news.uni-berlin.de...[color=blue]
          > Chung Leong wrote:[color=green]
          > > Yang Li Ke wrote:[color=darkred]
          > >> I know that there is a meta tag function to get all meta tags from a[/color][/color][/color]
          url.[color=blue][color=green][color=darkred]
          > >> I am searching for a similar function that would get all values of a[/color][/color][/color]
          form.[color=blue][color=green]
          > > Nope. What you can use is preg_match_all to find the names.
          > >
          > > preg_match_all( '/<input.*?name\\ s*=\\s*"?([^\\s>"]*)/i', $text,[/color][/color]
          $matches, PREG_PATTERN_OR DER);[color=blue][color=green]
          > > $names = $matches[1];[/color]
          >
          > This has been a fun dive into regexps :-)
          >
          > I just *love* PHP arrays!
          >
          >
          >
          > I run this from the shell prompt
          > pedro$ ./forminputs.php http://www.ebay.com/
          > ___UNNAMED_FORM ___0:
          > type=[hidden] name=[cgiurl] value=[http://cgi.ebay.com/ws/]
          > type=[hidden] name=[krd] value=[1]
          > type=[hidden] name=[from] value=[R8]
          > type=[hidden] name=[MfcISAPICommand] value=[GetResult]
          > type=[hidden] name=[ht] value=[1]
          > type=[hidden] name=[SortProperty] value=[MetaEndSort]
          > type=[text] name=[query] size=[25] maxlength=[300]
          > type=[submit] value=[Search] class=[buttonsm]
          >
          > ___UNNAMED_FORM ___1:
          > type=[submit] value=[Go] class=[buttonsm]
          >
          > ___UNNAMED_FORM ___2:
          > type=[submit] value=[Go] class=[buttonsm]
          >
          > popout:
          > type=[hidden] name=[popupurl][/color]
          value=[http://pages.ebay.com/merchpopup/sell2all_A.html][color=blue]
          >
          >
          >
          > code follows
          >
          > forminputs.php
          > #v+
          >
          > #!/usr/bin/php4
          > <?php
          > require_once 'forminputs.inc .php';
          >
          > $x = get_form_inputs ($argv[1]);
          >
          > foreach ($x as $form_name=>$co ntents) {
          > echo $form_name, ":\n ";
          > foreach ($contents as $inputs) {
          > foreach ($inputs as $k=>$v) if ($v) echo " $k=[$v]";
          > echo "\n ";
          > }
          > echo "\n";
          > }
          > ?>
          >
          > #v-
          >
          > and now forminputs.inc. php, with the function
          > #v+
          >
          > <?php
          > function get_form_inputs ($file_url) {
          > $retval = array(); // array that will be returned with the <input>s
          > $attrs = array('type', 'name', 'value', 'checked', 'disabled',[/color]
          'readonly',[color=blue]
          > 'size', 'maxlength', 'src', 'alt', 'usemap', 'ismap',
          > 'tabindex', 'accesskey', 'accept', 'id', 'class');
          > $form_count = 0; // used later to generate unique names
          > $html = file_get_conten ts($file_url);
          >
          > // forms cannot have forms inside
          > preg_match_all( '@(<form\s.*</form>)@isU', $html, $forms);
          > foreach ($forms[1] as $form) {
          >
          > // get the form name into $form_name, initialize with a unique name
          > $form_name = '___UNNAMED_FOR M___' . $form_count++;
          > if (!preg_match('@ <form[^>]+\sname="([^"]+)"@i', $form, $names)) {
          > preg_match('@<f orm[^>]+\sname=(\w+)@i ', $form, $names);
          > }
          > if (isset($names[1]) && $names[1] != '') $form_name = $names[1];
          >
          > // get the <input>s
          > preg_match_all( '@(<input\s[^>]*>)@iU', $form, $inputs);
          > foreach ($inputs[1] as $input) {
          >
          > // get the three important input attributes
          > foreach ($attrs as $a) {
          > // should make an array with all the attributes and use it in a
          > // loop
          > $v[$a] = false; ## default value
          > if ($a == 'type') $v[$a]='text'; ## default value
          > if (!preg_match('@ <input[^>]*\s'.$a.'="([^"]+)"@i', $input,[/color]
          $values)) {[color=blue]
          > preg_match('@<i nput[^>]*\s'.$a.'=(\w+) @i', $input, $values);
          > }
          > if (isset($values[1]) && $values[1] != '') $v[$a] = $values[1];
          > }
          >
          > // add the <input>s to a new element of the return variable
          > $retval[$form_name][] = $v;
          > }
          >
          > // no select? no textarea? no button? no label?
          > // no! :)
          >
          > }
          > return $retval;
          > }
          > ?>
          >
          > #v-
          > --
          > --= my mail box only accepts =--
          > --= Content-Type: text/plain =--
          > --= Size below 10001 bytes =--[/color]


          Comment

          • Pedro Graca

            #6
            Re: [code] Re: form tags?

            Yang Li Ke wrote:[color=blue]
            > Thank you very much for that function but Im getting an error with the
            > function undefined file_get_conten ts.
            >
            > Can you tell me why?[/color]

            <quote src="http://www.php.net/file_get_conten ts">
            PHP 4 >= 4.3.0
            </quote>

            So it seems your PHP is below 4.3.0
            Replace that call by

            $html = implode('', file($file_url) );
            --
            --= my mail box only accepts =--
            --= Content-Type: text/plain =--
            --= Size below 10001 bytes =--

            Comment

            Working...