Jump to content

Button clicks


feck

Recommended Posts

Do you mean something like this?

<?phpif(isset($_POST['submit'])) {echo "Your name is $_POST[name]<br />and your email is <a href='mailto:$_POST[email]'>$_POST[email]</a>";}else {echo "<form action='' method='post'><p>Name<br /><input type='text' name='name' /></p><p>Email<br /><input type='text' name='email' /></p><p> <br /><input type='submit' name='submit' value='Submit' /></p></form>";}?>

I tested the code, and it works. It's very similiar to the one in the PHP section at W3Schools, just that I made this on my own right now :)

Link to comment
Share on other sites

Sorry andersmoen,what I'm thinking of is something that will diplay the amount of times you click a button, by posting a variable back to itself after every click and redisplay the new value.I not too sure this can be done without using javascript, maybe I'm wrong.

Link to comment
Share on other sites

Solved it:

<?phpif(isset($_POST['count'])){		$var=++$_POST['count'];	}else{		$var= '1';	}echo "<form action='testButtonClick.php' method='post'><p>Counter:<br /><input type='text' name='count' value='$var'/></p><br /><input type='submit' name='submit' value='Submit' /></p></form>";?>

Pretty useless piece of code, I know, but just wanted too see how it could be done.Is there no other way of doing this apart from a full page refresh?

Link to comment
Share on other sites

Okay, you could have told us in the post before you know :)I guess you'll gonna have to find something else than the count() then. Search for ip counter at google.com or something. Maybe you'll get something then :)

Link to comment
Share on other sites

The testButtonClick.php was the script itself, did'nt know you could leave this out and achieve the same thing in the post method. Thanks for that, but both way's still require a full refresh.
If you don't want to refresh your page like the F5 way.. you can take a look at AJAX (Google some tuts & W3Schools tuts offcourse) :)
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...