(solved) Form submission

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
davidjwest
Forum Commoner
Posts: 67
Joined: Sat Nov 06, 2004 5:26 am
Location: Leeds, Yorkshire, England

(solved) Form submission

Post by davidjwest »

I have a simple form which needs submitting, it will then send the details to me by email. After the submit is pressed I want to include a different bit of code.

Code: Select all

<?php
echo "<form method='post' action='mailto:david@foo.org'>";
?>
The problem is where do I put the "echo $_SERVER['PHP_SELF']" so that the code knows the button has been pressed?

Code: Select all

<?php
echo "<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">";
?>
Can I have two actions?

Thanks.
Last edited by davidjwest on Thu Sep 01, 2005 2:36 pm, edited 1 time in total.
davidjwest
Forum Commoner
Posts: 67
Joined: Sat Nov 06, 2004 5:26 am
Location: Leeds, Yorkshire, England

Post by davidjwest »

It appears you can't have two actions on one form, it just executes the first occurence.

Any ideas?

The other bit of code is:

Code: Select all

<?php
if (isset($_POST['submit']))
 {
  include "centre.php";
 }
?>
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

the action attribute tells the form what to do when submit is clicked. It does not notify anything that something's been done.
$_SERVER['PHP_SELF'] evaluates to the filename of the current script. Therefore, if you put action='{$_SERVER['PHP_SELF']}', then it merely reloads to the same page with the given GET/POST variables set.

Also, you have a big error in your syntax:

Code: Select all

<?php
echo "<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">";
?>
you have <?php ?> imbedded INSIDE OTHER <?php ?> tags. O.O PLUS, you have " imbedded inside other "!!
With your code, it does something like this...
1) echos "<form action="
2) wtf? <?php is already open!! error.
should be something like this:

Code: Select all

<?php
echo "<form action='{$_SERVER['PHP_SELF']}' method='post'>";
?>
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

wait, I think I see what you're getting at. When action is set to an email address, it doesn't reload the page when you click submit? If that's so, just use javascript to reload it. ;)
Post Reply