Page 1 of 1

Form action on the same page

Posted: Mon Aug 18, 2008 5:59 pm
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

Re: Form action on the same page

Posted: Mon Aug 18, 2008 6:03 pm
by Stryks
Have you read THIS thread?

Re: Form action on the same page

Posted: Mon Aug 18, 2008 9:55 pm
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    
    }
}
?>