View Full Version : Checking if the user has submitted a form
foodpk
December 18th, 2005, 06:54 AM
I have a form on one page (it's form.php) and the action="form.php" method="post" on the form. At the end of the form I have <input type="submit" name="submit" value="submit">. And then I have a big if/else tree that checks isset($_POST['submit']) and if it is set then it goes on to checking if all the required fields have been filled out and if it isn't it just displays the form. Simple enough so far.
But what if I want to get rid of the submit button and use a link instead (<a href="javascript:document.forms[0].submit()">)? How would I then go about checking if the user came to that page via submitting the form or just coming there normally.
Thanks.
EDIT: Wow, just my luck, I seem to have submitted this under the client side section instead of the server side. Can a mod please move it? thanks
Ben H
December 18th, 2005, 07:06 AM
if (isset($_POST)) {
//Your code
} else {
//Your other code
}
-Ben
Phlashman
December 18th, 2005, 07:06 AM
Any reason why you need to check to see if the userr submitted the form? Why not just check the required fields? Whatever type of security level you are attempting to acheive seems rather pointless to use a Submit variable. I don't understand what you need. However, this post from php.net may be of use to you:
http://us2.php.net/manual/en/reserved.variables.php#56992
Hope that helps ;).
Ben H
December 18th, 2005, 07:22 AM
Phlashman, that checks the referrer to the form, not the values, he is parsing form data on the same page it is submitted from, so he needs to check whether or not it has been submitted.
-Ben
Phlashman
December 18th, 2005, 07:25 AM
Well he already said that he first checks whether the submit button was pressed, and then that all the fields were filled out and filled out correctly. So I'm wondering what the problem is.
foodpk
December 18th, 2005, 07:29 AM
Thanks om3ga, i'll try that!
Phlashman, the thing is if I just checked the field variables then everytime the user came to that page with the form it would say that he hasn't filled in the required fields even though the user probably didn't even submit a form.
Phlashman
December 18th, 2005, 07:34 AM
Oh! Well, come to think of it, you could easily just use a hidden input. Say, call it submitted and give it a value of yes. Then, in your PHP code, say:
if ($_POST['submitted'] == 'yes'){
or whatever you want...
foodpk
December 18th, 2005, 07:39 AM
Phlashman that's a cool idea too! Thanks!
By the way guys, one more question. When sending mail via the mail() function can I just use normal html formatting in a string so that then browsers that support html will view it as html? Like "<html><head><style> blah blah"
Any stuff I should take care of when sending mail this way?
Phlashman
December 18th, 2005, 09:02 AM
I was wondering that too. I've tried to send mail using a form. So in the form, I would write, <b>, for example. The problem is that I believe that it is recorded as < and %gt; and then displayed that way in the email. Because of this, it is not bold but just shows the HTML tags. I was wondering how to do this myself. This would be useful.
EDIT: Found an HTML tag unescaper!
http://pure-essence.net/stuff/code/utf8RawUrlDecode.phps
EDIT 2: It appears PHP does have a normal function (non UTF-8) to unescape those HTML tags:
http://us2.php.net/urldecode
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.