PHP orientation: Form Required Fields



Dear PHP'users

I am sorry that I must announce I am a total newbie. Right now I am busy with my education where I want to orientate on PHP and ASP.NET. It's not neccesary for me to fully understand PHP (or ASP.NET), but I just have to compare the two languages. So I don't want to get too deep into understanding PHP yet.

That's why I may have a question where you might think: "Come on, try a little harder". Still, I hope you will help me, for I think this is the easiest question you ever had :) .

I have a form in ASP.NET where, if you do not fill in required fields, a message POPS UP right next to where - in example - you have to fill in your name.

Here is an example:

This example is a bit messy. You have to go all the way down to the form, submit it without entering anything, scroll down again, and you see what I mean.

Is this possible with PHP? For I have searched for hours and could only find forms where if you don't enter a required field, it generates a total new page with the error message! So you have to click on the BACK-button to go back to the form.

I hope you understand me and are willing to help.


It is possible, what you have to do is to pass the form values to be processed. Then, depending on their validity, you just output the value in a certain format.

This case has nothing to do with PHP or ASP. This is a Client-Side case.
Of course you can handle that with PHP, ASP or ... whatever Server-side language, but... there's no need for that!

The code that is used to handle the forms data is in Javascript.
Just check the source code of the the page you gave us and you'll see.
good responce gesf. here comes a little correction: The need is for 100% compatibility as some users disable JS and therefore some things might not work at all.. including validation. With server-side validation this problem disappears but you get a bit mroe things to do.. plus you will have to reload all the data again in case of error... this sucks pretty much: but its more secure.

Regarding php and in general: the problem with (and even worse ASP) you will have to write tons of code to do ANYTHING. if you compare to PHP code it will be much more compact and easier to read/manage. The banchamrking of PHP wins without no doubt. Plus the problem is that its impossible to run in full scale on Other platforms but windows. Yes, i know there is Mono and such but they do not use the default .net framework but make more or less their own and some functions do not work.

On windows is possible to run full scale only using IIS : very unstable and insecure in comparison to Apache. Ofcource, once again there is a module for Apache to run but this is simply a workaround.

PHP can also handle more users on the same machine in comparison to and PHP also has a very tight integration with Java.
I can go on in comparing them for hours but you still have to see for yourself. Ofcource its possible to create webservices with both and with it might be a bit easier to communicate with Client Applications (Windows apps) as may already have a class for that or simmilar... But a real developer doesnt need that and thats why we have no problems at all in writing our own gateways.
Hello all

Thanx for the replies. I was kind of surprised to hear it was javascript. I once had written ASP.NET code which I thought did not have any javascript (from a tutorial book).

I found the code! So here it is:

<form runat="server">
<p>User name:<br />
<asp:TextBox id="username" runat="server" /><br />
<asp:RequiredFieldValidator id="rfvUsername" ControlToValidate="username"
ErrorMessage="User name is required!" runat="server" /></p>

This is all to activate required fields in ASP.NET. Since I can not find anything shorter in PHP (most codes even require 2 files!!) this one is best?

I am very curious to your reactions, because my essay is about PHP vs. ASP.NET

Thank you!
MeanRat (Maarten)
okey..well.. the reaction would be that thats a pre defined templating and such exists for PHP as well... there are several templating engines that are powerfull enough: Smarty is one of them.

There isn't much what i can tell you.. but the thing is that validation is possible to cause through server side as well... its safer and such...

Even in asp as this is simply a tempalte engine that does the work for you... Such things are not really needed as they dont give you the full power that you have while writing such codes for yourself...

I am not a professional and therefore cannot fully compare them.. but I know one thing: i will not change PHP for it.. that for sure.. after all: there is nothing that can do and PHP cant.. however has much worth support for other platform. Even Mono is simply an open source project..not approved by MS..

Plus like i said: PHP has greater speed, stability and requires less code :)