Jump to content

Form button action


marb

Recommended Posts

Hi,

I'm new here and I'm learning PHP.

 

I'm trying to do a little script to print a message after push an HTML button, but the message appears before I push the button. When I have a textbox, I can control that with the instruction" if isset($_Post[text var])", but without the textbox I can't do it.

 

Help me please. Here is the sample:

 

 

<html>
<body>
<form " method="post">
<input type="submit" value="Msg" name="submit" /></p>
</form>
</body>
</html>
<?php
echo "Hello";
?>

 

 

 

Link to comment
Share on other sites

That's not how PHP works.

 

PHP does all the work on the server before any of the HTML takes relevance. When PHP is done it generates the HTML code and sends it to the user's computer. The computer only sees the HTML.

 

After your PHP script is finished, what's sent to the user is this:

<html><body>  <form " method="post">    <input type="submit" value="Msg" name="submit" /></p></form></body></html> Hello
Your <form> needs an action attribute to be useful.
In your case, the submit button itself is a form element with name "submit" so you can choose to only show content if that element is found
if(isset($_POST[submit'])) {    echo "Hello";}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...