Jump to content

New to PHP - Issue with processing a form


scrgeek

Recommended Posts

I have two test files set up as simple forms.  For all practical purposes, they are identical with the exception of the how the php is called.  Both files use the same php file to process the data.

 

In the first case (test1.html), the php is called directly by the action method, and works:

<form class="pWriteShort" id="contact" action="test.php" method="post">

 

The second case (test2.html) calls the php with an include statement and global $_SERVER call as below:

<?php include '/test/test.php'; ?>

<form class="pWriteShort" id="contact" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
 
In the second case, it leads to a server generated 404 error.  I know I must be doing something stupid, but for the life of me, I can't find it.
 
If further info is needed, the files are here:
 
Thanks, in advance, for any help.
 
Regards,
Sam Rogers

 

Link to comment
Share on other sites

The html files are just the forms... the validation is php.  

 

You have PHP code in the action attribute for an HTML page. That code will not get processed and the HTML page will not know what to do with it.

 

Let me try to explain in a different way:

 

When a user requests a page from a websesrver, the webserver will first check to see if that page exists. Then, determining on the type of page that it is and how the server is configured, it can do different things with that request.

 

 - When requesting a page with a .htm or .html page the server will simply send the raw file to the user as is and the browser will display the page to the user.

 

- If the requested page has an extension of .php (or some other server-side language it is configured for), the server will find that file and then send it to the PHP process to execute the code in that page - then send the results of the output from that code to the user.

 

So, on your HTML page with this:

<form class="pWriteShort" id="contact" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">

Since the page was not sent to the PHP processor (because it has the extension of HTML) the action in the HTML page will be <?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>. The browser cannot process PHP code and would not know where to send the form.

Link to comment
Share on other sites

So, can the php page contain html and render that properly and then send that to the client's browser?  Please pardon my stupidity... I just started trying to learn this yesterday.

 

On another note, I did not see the note to not post this in the welcome area, but I couldn't find an option to delete the post.  I'm sorry for breaking the rules on my first post.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.