How can I execute a PHP function in a form action?

php

Question

I am trying to run a function from a PHP script in the form action.

My code:

<?php
require_once ( 'username.php' );

echo '
<form name="form1" method="post" action="username()">
  <p>
    <label>
      <input type="text" name="textfield" id="textfield">
    </label>
  </p>
  <p>
    <label>
      <input type="submit" name="button" id="button" value="Submit">
    </label>
  </p>
</form>';
?>

I echo the form but I want the function "username" which is called from username.php to be executed. how can I do this in a simliar way to the above?

1
25
2/27/2009 4:09:52 PM

<?php
require_once ( 'username.php' );

if (isset($_POST['textfield'])) {
    echo username();
    return;
}

echo '
<form name="form1" method="post" action="">
  <p>
    <label>
      <input type="text" name="textfield" id="textfield">
    </label>
  </p>
  <p>
    <label>
      <input type="submit" name="button" id="button" value="Submit">
    </label>
  </p>
</form>';
?>

You need to run the function in the page the form is sent to.

20
2/27/2009 4:04:47 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon