The detritus of a Button Monkey

22 Mar

Writing forms in php

I have been playing around with forms for a while now, both in my project and personally. I must admit that sometimes I use a book example, modify to what I need and move on without fully understanding how. One example is form action.

Previously I have used this king of code:

<form action=”submit.php” method=”post”>

…and everything works fine because the script is called submit.php. The variables are being sent to this script for interpretation.

Whilst following some book examples, I have changed the why I write my forms without understanding why I have changed. This notation is:

<form action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>” method=”post”>

The advantage with this is that this line will work in ANY page without being changed. This is because the php statement is basically saying “send the data to this page”. The previous statement needs to be changed to reflect the name of the page. This means that the earlier version requires modification if the file name changes.

The two statements do the same thing.

Leave a Reply

You must be logged in to post a comment.

© 2022 The detritus of a Button Monkey | Entries (RSS) and Comments (RSS)

Design by Your Index - Powered By Wordpress