Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2000071

Re: [PHP] #2 Form Problem w/multiple forms same page. From: Kenneth Bogucki (k.bogucki <email protected>)
Date: 07/12/00

as per request:

Hope this helps, however, I'm sure there are simplier ways to code this!

ken

Note: the submit buttons must have a name value field for this to
work.....you can use the same name or different names...works both ways.

<form method="post" action="test45a.php3" name="test">
  <p>
    <select name="dbname">
      <option value="0">no selection</option>
      <option value="1">selection one</option>
      <option value="2">selection two</option>
    </select>
  </p>
  <p>
    <input type="text" name="simpletest">
    <input type="submit" name="querysub" value="simple">
  </p>
  <p>
    <input type="text" name="complextest1">
    <br>
    <input type="text" name="complextest2">
    <br>
    <input type="text" name="complextest3">
    <input type="submit" name="querysub" value="complex">
  </p>
  </form>

============

test45a.....

This below code will print out to the browser the values sent to
test45a.php3 ....if the complex button is pressed then the querysub
variable from the form will equal the value "complex", if the simple
button is pressed then the querysub variable will have the value
"simple"

Normally you would not print these values to the browser but use the
values to determine the type of query, the query variables and the db
name to search...

something like:

if querysub equals complex then use only the complex query values and db
name, elseif same for simple, else....some kind of error message in the
event someone bookmarked the results page instead of the main search
page.

FWIW you can also reference the variables from the submitted form,
without using HTTP_POST_VARS by simply using the name in the form as a
variable, $querysub, $complextest2, $complextest3, etc. I haven't tried
this, but should work.

begin code---------------
<?php_track_vars?>
use the above only if the track_var option is off in you ver. of
PHP...must be the very first line of code on the html page
<html>
rest of html code.....

<?

  if ($HTTP_POST_VARS)
      {
      for(reset($HTTP_POST_VARS); $key = key($HTTP_POST_VARS);
next($HTTP_POST_VARS))
      {
      if (is_array($HTTP_POST_VARS[$key]))
          {
          $num=count($HTTP_POST_VARS[$key]);
          for ($i=0; $i<$num; $i++)
              print "$$key". "[$i] = ".$HTTP_POST_VARS[$key][$i].
"<br>\n";
          }
      else
          {
              print "$$key = ".$HTTP_POST_VARS[$key]. "<br>\n";
          }
      }
      }

  ?>

</body>
</html>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe <email protected>
For additional commands, e-mail: php-general-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>