Forum Moderators: coopster
need a way to chcek if a form button was pressed. i have a comment form and when sumbit si pressed some proocessing, just that i dont want to call a another script when button is pressed, prefer to have everything in the same file, so that inlcuding it elsewehere is simple
any sugessitons...u still around minkler..? ;)
k
lol. You can also get input from your 'submit button' as well as from normal input fields, radio / checkboxes etc. I.i.r.c. for a 'special form' you just have to use <input type="submit" name="thisname" value="Go!">. Then (say if you're using post) $_POST['thisname'] == 'Go!' if this was the button clicked for that particular form. Thing is, "name" is usually left out in the input fields of type "submit", but you can still use this if you need this.
You have another 'non-special' form that's not the 'special form' that either doesn't name it, or doesn't use the value 'Go!' and instead says 'submit this'. Then in the form script:
if($_POST['thisname'] == 'Go!') {
/* do the special stuff for that special form / button */
} else {
/* do the other non-special stuff */
}
You can probably also do the same with just one form, but with two different submit buttons named different things. I know I've tried this, though not in production, just can't remember how it all came out. Basic key is: <input type="submit"> can also have a relevant "name" and "value".
That said, if you have two different submit forms that go to the same script, don't forget that you have <input type="hidden" name="this" value="that">. Your user won't see anything of all of this stuff, but $_POST['this'] == 'that' in your action script. Also, you can add as many of these 'hidden' fields as you want, which is brilliant of course.
Hope this answers your question to some degree. You should really sticky me your url so I can admire your work until now ;)
echo '<form method="POST" name="metsign" action="">
<strong>Make a comment</strong><br><br>
Name<br><input type="text" name="name" size="20"><br>
<input type="hidden" name="date" size="20"><br>
Comment<br><textarea name="comment" rows="5" cols="20"></textarea><br />
<input type="submit" name="submit" value="OK">
</form>';
if (isset($_POST[submit]))
{
echo 'cool';
}
?>
but following notice occurs...
any ideas?
k
Notice: Use of undefined constant submit - assumed 'submit' in c:\program files\easyphp1-7\www\test\comment.php on line 34