Jump to content

Recommended Posts

I have seen a lot about preventing form submission when somebody hits the enter key.  My question is a little different.

 

I usually use an image to submit all forms.  Then, when a user clicks, I test using PHP like this:

 

if (isset($_POST['submitButton_x']))

//do this

 

When I have two or more fields, this works just fine whether somebody hits ENTER or clicks the button.  It gives button coordinates if it was clicked and 0,0 otherwise.  However, when I only have ONE field, if the user clicks enter, it does not register anything for the submitButton_x or y.  So, the form essentially does not get submitted at all. 

 

Also, putting a second hidden element does not change it.

 

Has anybody else had this issue.  If so, how did you fix it?

Link to comment
https://forums.phpfreaks.com/topic/64406-solved-html-form-image-question/
Share on other sites

You could try looking for contents in the text field.

Example:

<html>
<head>
</head>
<body>
<form action="script.php" method="post">
<input type="text" name="textbox" value="Data" onclick="this.value=''">
<input type="submit" name="submit" value="submit">
</form>
<?php
if (empty($_POST['textbox'])){
?>
No data or form not submitted.
<?php
} else {
?>
The form was submitted.
<?php } ?>
</body>
</html>

???

 

onclick is an eventhandler for calling javascript (or vbscript if you are stupid enough to use is).

 

My concern here is that in each case you are trying to override the default behaviour of a browser. My advice would be to use just submit buttons that are styled (MAC's will swap the image input for its own glass button anyway) and let the browser do what ever it does.

 

You will find browsers do NOT handle the image input the same way - some pass the co-ordinates clicked other just the fact it was clicked.

 

So where possible use mark-up that will work on a text-only browser and use css to make it look good.

 

By all means do some js client side checks if you want but ensure you validate ALL user input server side too.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.