Form action on the same page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
glennnz
Forum Newbie
Posts: 9
Joined: Thu Aug 14, 2008 7:16 am

Form action on the same page

Post by glennnz »

I've been reading about how to do this, and can't find a decent answer.

I want to use a form to post some information to a php function on the same page. How do I do this?

Something like:

<html>
<form method="post" action="#">
<input type="text" name="parameter">
<input type="submit" name="Calculate"
</form>

<?php
- the php code that uses 'parameter' and does something with it -
?>
</html>

Thanks

G
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Re: Form action on the same page

Post by Stryks »

Have you read THIS thread?
User avatar
swiftouch
Forum Commoner
Posts: 80
Joined: Sun Dec 10, 2006 7:35 am
Location: Salt Lake City, Utah

Re: Form action on the same page

Post by swiftouch »

Ima beginner(have been for years) so I'm happy-go-lucky when I can actually answer a question.

The way I do it is simple.

In the "action=" put a ? and do=whatever...like this...

Code: Select all

<form name="form1" id="form1" action="?do=sendmail"  method="post">
This way when posting, it will turn into a GET variable you can test for on the same page. For example, like this:

Code: Select all

 
<?
if (isset($_GET['do'])) {
# mail actions
    switch($_GET['do']) {
        #code    
    }
}
?>
 
Post Reply