Jump to content
Larry Ullman's Book Forums

Html Function 'Form' Not Working


Recommended Posts

Greetings, great book and I plan to 'slowly work my way' through each page. My first 'road block' has occured with the scripts 'form.html' and 'handle_form.php'.

 

The HTML and PHP editor is Rapid PHP 2007, the Dell Laptop, Windows Vista Business, IIS7 is installed and working, PHP5 installed and working.

 

The info.php file with the script <?php phpinfo(); ?> in line #1 works, either from the Rapid PHP 2007 editor of when double clicking the file will 'find the server', loads the file into the MSIE and does work.

 

When the file 'handle_form.php' is resident in the Rapid PHP 2007, previewing this fifle in MSIE, the script works except no variables have been passed from 'form.html'.

 

'form.html' does work and 'the problem' is passing data into 'handle_form.php'. This file is not loaded into MSIE but the message is to open this file into the clipboard.

 

Thus, I am not too sure what 'my problem' is. It seems and use of the HTML code <form action="handle_form.php" method="post"> will not 'load the form' in to MSIE, but will open this file into the clipboard.

 

This 'road block, speed bump' in getting on with things is quite firm. Not good.

Link to comment
Share on other sites

Hi i'm not 100% sure what your set up is here. When you say

This file is not loaded into MSIE but the message is to open this file into the clipboard.

Do you mean that when you try to open handle_form.php it won't open it and tries to open it in your editor.

 

If so what URL are you trying to open the file with?

 

It also could be helpful that you post your code for the two files using the code tags. As i'm still not 100%sure if this is a set up error or coding error ;)

  • Upvote 1
Link to comment
Share on other sites

Yeah, things are a little vague. I'm not familiar with that HTML/PHP editor. Sorry. Like Jonathon said, if you could please post your code, that would be helpful.

 

However, if your code is identical to the code and the book (and you're sure that there are no syntax errors), then the issue might be with the setup of your PHP editor.

 

Personally, I prefer to use XAMPP (a free program that provides a virtual server) and a separate text editor (I prefer Notepad2). Again, it's hard to know the issue for certain without looking at your code, but if you just copied the code from the book, then it's probably an issue with your test environment (i.e., some settings in Rapid PHP 2007).

  • Upvote 1
Link to comment
Share on other sites

Greetings, great book and I plan to 'slowly work my way' through each page. My first 'road block' has occured with the scripts 'form.html' and 'handle_form.php'.

 

The HTML and PHP editor is Rapid PHP 2007, the Dell Laptop, Windows Vista Business, IIS7 is installed and working, PHP5 installed and working.

 

The info.php file with the script <?php phpinfo(); ?> in line #1 works, either from the Rapid PHP 2007 editor of when double clicking the file will 'find the server', loads the file into the MSIE and does work.

 

When the file 'handle_form.php' is resident in the Rapid PHP 2007, previewing this fifle in MSIE, the script works except no variables have been passed from 'form.html'.

 

'form.html' does work and 'the problem' is passing data into 'handle_form.php'. This file is not loaded into MSIE but the message is to open this file into the clipboard.

 

Thus, I am not too sure what 'my problem' is. It seems and use of the HTML code <form action="handle_form.php" method="post"> will not 'load the form' in to MSIE, but will open this file into the clipboard.

 

This 'road block, speed bump' in getting on with things is quite firm. Not good.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

<title>Simple HTML Form</title>

</head>

<body>

<!-- Script 2.1 - form.html -->

 

<form action="handle_form.php" method="post">

 

<fieldset><legend>Enter your information in the form below:</legend>

 

<p><b>Name:</b> <input type="text" name="name" size="20" maxlength="40" /></p>

 

<p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="60" /></p>

 

<p><b>Gender:</b> <input type="radio" name="gender" value="M" /> Male <input type="radio" name="gender" value="F" /> Female</p>

 

<p><b>Age:</b>

<select name="age">

<option value="0-29">Under 30</option>

<option value="30-60">Between 30 and 60</option>

<option value="60+">Over 60</option>

</select></p>

 

<p><b>Comments:</b> <textarea name="comments" rows="3" cols="40"></textarea></p>

 

</fieldset>

 

<div align="center"><input type="submit" name="submit" value="Submit My Information" /></div>

 

</form>

 

</body>

</html>

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

<title>Form Feedback</title>

<style type="text/css" title="text/css" media="all">

.error {

font-weight: bold;

color: #C00;

}

</style>

</head>

<body>

<?php # Script 2.5 - handle_form.php #4

 

// Print the submitted information:

if ( !empty($_POST['name']) && !empty($_POST['comments']) && !empty($_POST['email']) ) {

echo "<p>Thank you, <b>{$_POST['name']}</b>, for the following comments:<br />

<tt>{$_POST['comments']}</tt></p>

<p>We will reply to you at <i>{$_POST['email']}</i>.</p>\n";

} else { // Missing form value.

echo '<p class="error">Please go back and fill out the form again.</p>';

}

?>

</body>

</html>

 

 

Both of these files are moved/copied from 'their unziped' location over into the C:\inetpub\wwwroot directory.

Link to comment
Share on other sites

Hi i'm not 100% sure what your set up is here. When you say

 

Do you mean that when you try to open handle_form.php it won't open it and tries to open it in your editor.

 

If so what URL are you trying to open the file with?

 

It also could be helpful that you post your code for the two files using the code tags. As i'm still not 100%sure if this is a set up error or coding error ;)

 

 

<form action="handle_form.php" method="post">

 

<fieldset><legend>Enter your information in the form below:</legend>

 

<p><b>Name:</b> <input type="text" name="name" size="20" maxlength="40" /></p>

 

<p><b>Email Address:</b> <input type="text" name="email" size="40" maxlength="60" /></p>

 

<p><b>Gender:</b> <input type="radio" name="gender" value="M" /> Male <input type="radio" name="gender" value="F" /> Female</p>

 

<p><b>Age:</b>

<select name="age">

<option value="0-29">Under 30</option>

<option value="30-60">Between 30 and 60</option>

<option value="60+">Over 60</option>

</select></p>

 

<p><b>Comments:</b> <textarea name="comments" rows="3" cols="40"></textarea></p>

 

</fieldset>

 

<div align="center"><input type="submit" name="submit" value="Submit My Information" /></div>

 

</form>

 

does not load into MSIE passing the variables from form.html into handle_form.php but opens this file in the clipboard. Yet, when handle_form.php is resident in the editor, clicking preview tab or preview in button on the tool bar the handle_form.php does execute the php code but no variables are passed from form.html.

 

What is of great importance is a 'complete understanding of this <form action="handle_form.php" method="post"> HTML method as the prime objective will be close work with MySQL.

Link to comment
Share on other sites

"clicking preview tab or preview in button on the tool bar the handle_form.php does execute the php code but no variables are passed from form.html."

 

But you never say that the script should DISPLAY any of your variables. You just check if they are not empty, then display the name of the comment poster.

 

I don't know why the file is opened in clipboard.

 

An easy thing to do is to uninstall PHP5 from your machine and install XAMPP. It's very easy to set up and requires a PURE minimum of configuration.

Setting it up will take less than 15 minutes the first time. I think that would solve your problem faster.

Link to comment
Share on other sites

"clicking preview tab or preview in button on the tool bar the handle_form.php does execute the php code but no variables are passed from form.html."

 

But you never say that the script should DISPLAY any of your variables. You just check if they are not empty, then display the name of the comment poster.

 

I don't know why the file is opened in clipboard.

 

An easy thing to do is to uninstall PHP5 from your machine and install XAMPP. It's very easy to set up and requires a PURE minimum of configuration.

Setting it up will take less than 15 minutes the first time. I think that would solve your problem faster.

 

If MS MySql was not installed and working along with PHP5 both of which is necessary for Wordpress to also be installed and also working, then the simple thing could be try XAMPP.

 

Except, wordpress is installed and 'things are working', Microsoft IIS7 is installed and working. Even the most simple task, a simple 1 element form cannot seem to POST one variable onto a second .php page.

Link to comment
Share on other sites

See what Larry said. You have mentioned that you are double-clicking the file to launch it -- that's most likely causing your problem. You must run any PHP file through a URL, which means typing the address. If your form.html is in the root of your IIS server, just type //localhost/form.html in the address bar of your browser. It should work then.

 

The reason for this is if you double-click a file the protocol will be FILE://, not http://, so the file is not run through the web server, the browser just opens it up. When the web server finds a file with a PHP extension it will (assuming PHP is properly installed) run the file through the PHP interpreter and your code will be parsed and executed. If you double-click the file, your browser will open it up like any html file, and not finding any html, displays plain text; which is what you are seeing.

Link to comment
Share on other sites

I expect that you're not running the form.html page through a URL (i.e., http:// something).

 

And, of course, you got that right.

 

I have 'discovered just what was the fault or at least what is needed for 'things' to function as planned.

 

Changing <form action="handle_form.php" method="post"> to now

 

<form action="http://localhost/handle_form.php" method="post"> is what is necessary to 'get things to work'.

 

This is no doubt to suggest that the file handle_form.php is to be 'given to the server' who then passes it onto MSIE. Of course, MS IIS7 already knows what it need to know about PHP5.

 

This is to suggest all applications (on this learning about it system) will require <form action="http://localhost/(some .php file)" to be used.

 

Also, somewhere I did read about the use of 'single quotes' as well as "double quotes". I do believe this is of some importance, just another detail on this path of a wonder through the forest of trees on knowing things.

Link to comment
Share on other sites

The alternative, which you'll need to start doing eventually, is loading the first page (the form) through a URL. I don't know how this is done using your particular IDE, but you'll need to start doing that soon anyway.

 

I believe technically HTML element attributes should use double quotation marks.

Link to comment
Share on other sites

 Share

×
×
  • Create New...