I am trying to use PHP and HTML Forms from a node that is a static page, with PHP enabled.

The node displays the text fields and the button fine, but does not process them when I click on the button. It redirects to the http://mysite.com/node page for some unknown reason.

How can I get this working?

Here is some sample code I am using:

$this_script=$_SERVER["REQUEST_URI"];

print "fname=$edit['fname'] $fname lname=$edit['lname'] $lname";

if ($edit["fname"] || $edit["lname"])
 {
 // Capitalize the name
 $full_name = ucwords ($edit["fname"] . " " . $edit["lname"]);
 print "Hello! Nice to meet you <b>$full_name</b>...";
 print "Glad to see that you are using my form!";
 }

$form  = form_textfield (t("First Name"), "fname", "", 30, 64);
$form .= form_textfield (t("Last  Name"), "lname", "", 30, 64);
$form .= form_submit    (t("Process"));


print form($form, "post", $this_script);

Any help appreciated.

Comments

dries’s picture

Try dropping the "post" and $this_script parameters from the call to form() (the parameters are optional) ...

print form($form);

or try setting $this_script to $_GET['q']:

$this_script = $_GET['q'];
kbahey’s picture

Thanks Dries for your response.

I tried both, but neither works.

Same symptom (when the "Process" button is pressed, I get the /node page)

I also tried it with the "Process" button called "Submit", but that confused it, and caused /tracker to report some nodes with empty titles!

Any more ideas? The basic requirement here is to be able to do what I used to do in PHP from Drupal (forms, ..etc.)

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

gerardryan’s picture

i use this one that i dug up on the web and modified for my own use. it does email/phone validation as well.

demo here:
http://www.avi.org/feedback

the source is here:
http://www.avi.org/feedback.phps

remember to ditch the opening/closing php tags and to also set the action value to your script's URL (only way i was able to make it work as desired).

kbahey’s picture

Here is the solution.

Thanks to all who helped.

Remember, this is dynamic PHP inside a static page, and not a module on its own.


$fname = $_POST['edit']['fname'];
$lname = $_POST['edit']['lname'];

if (isset($_POST['Process'])) 
 {
 // Capitalize the name
 $full_name = ucwords ($fname . " " . $lname);

 print "<p>Hello! Nice to meet you <b>$full_name</b>...</p>";
 print "<p>As you see, we have capitalized the first letter, and spelled the full name</p>";

 print "<p></p><p></p><p></p>";
 }

$o  = "";
$o .= form_textfield ( "First Name", "fname", "$fname", 33, 64);
$o .= form_textfield ( "Last  Name", "lname", "$lname", 33, 64);
$o .= form_submit ("Process", "Process");

$f = form($o);

print $f;

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

Mr Maggoo’s picture

How would I make it so that it entered the info into a database?

Thanks

Mr Maggoo