EagerWolf Posted February 16, 2007 Share Posted February 16, 2007 Hello! I have got form.php, which generates forms, and in the same file I need to put few lines which are excecuded if form is submitted. so form action must be <?php echo $_SERVER['PHP_SELF'] ?> ... How do I create if statement then? Thanks for yout help! Best regards, M Quote Link to comment https://forums.phpfreaks.com/topic/38792-solved-forms-submit/ Share on other sites More sharing options...
boo_lolly Posted February 16, 2007 Share Posted February 16, 2007 it's very simple. there are a few ways to do it, it really depends on what your page looks like and what you've got going on. example: <?php if(isset($_POST)){ /*execute code here*/ unset($_POST); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/38792-solved-forms-submit/#findComment-186590 Share on other sites More sharing options...
Archadian Posted February 16, 2007 Share Posted February 16, 2007 Here is some code i wrote just testing out everything: <?php $email = "email"; $ne = "no email"; echo "<table align=\"center\" width=\"50%\" height=\"10%\">"; echo "<tr>"; echo "<form ACTION=\"" . $_SERVER['PHP_SELF'] . "\" METHOD=\"POST\">"; echo "<td align=\"center\" width=\"100%\">"; echo "<INPUT TYPE=\"text\" NAME=\"email\">"; echo "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Send\">"; echo "</td>"; echo "</form>"; echo "</tr>"; echo "<tr>"; echo "<td align=\"center\" width=\"100%\">"; if (isset($_POST['email']) && $_POST['email'] == $email) { echo "EMAIL!"; } elseif (isset($_POST['email']) && $_POST['email'] == $ne) { echo "NO EMAIL"; } else { echo ""; } ?> in this if i type "email" in the text area and hit submit "EMAIL shows up under it. If i type "no email" then NO EMAIL shows up under it. If i type anything other than those 2 nothing shows up hence the echo " ";. I hope this helps as far as your forms and $_SERVER['PHP_SELF']; Also if you don't want a script run until the user clicks submit then you can do: if (isset($_POST['submit'])) { //put the info here that the form redirects to, in this case action=\"$_SERVER['PHP_SELF']\" } else { echo "Please fill out the form and click Submit."; } that way they can't just go to the page that pulls info or inserts info into the DB from the form. Figured i would throw that in. Just a small security messure. I hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/38792-solved-forms-submit/#findComment-186601 Share on other sites More sharing options...
EagerWolf Posted February 16, 2007 Author Share Posted February 16, 2007 Thanks for your help! That is what I wanted! Best Regards, M Quote Link to comment https://forums.phpfreaks.com/topic/38792-solved-forms-submit/#findComment-186665 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.