this may be more of an html question but relates to php...
I have a form with multipal text fields. when in any field you press the enter key the form is submitted to php, eventhou the form is not compleat.
what would be a method for detecting or traping this event?

is there a "hey STUPID finish the form" function?

thanks much

Not knowing PHP, it'd probably be just an if statement of some sort, perhaps? If fieldname=NULL, then throw some kind of notification?

Javascript can do it

What if JavaScript is disabled?


You can find your answer in probably every PHP-tutorial. If you send your form with the <form action="script.php" method="post"> tab, then you'll get a $_POST for every field of your form. So you simply check if every field is complete:

if (!$_POST['fieldname'])
	echo "<div style='color:red'>"."Please fill out this field!"."</div>";

That's it basicly.



Yes, that's how I would do it server side. However, I think he wanted a client side solution to his problem (i.e. a box that pops up if you try without filling it out).

For the client, it's no difference whether the script is parsed on the server (php) or runs on the client (JavaScript).


That's true for most people. People with slow connections will want it on the client.

I think he wanted a client side solution to his problem

I think the OT mentioned php, but hey, we are talking, and he isn't even responding.


thanks everone for your efforts, I have been distracted by personal events, and as programing and computing in general is not a daily profession for me I am alway as diligent in followups as I should be.
I was hoping that there would be some properity of html that would restrict the action of the enter key. if not, then java script seems like the way to go.
again thanks.

you can use a simple if-then function and a strlen to get the length of the text entered by the user

the trim functions is used to make sure they didnt just enter spaces as there input.

if (strlen(trim($user_input)) < 1)
  echo "hey STUPID finish the form";
This article has been dead for over six months. Start a new discussion instead.