processing a form action in 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
thelondonstyler
Forum Newbie
Posts: 3
Joined: Thu Mar 26, 2009 12:10 pm

processing a form action in the same page

Post by thelondonstyler »

Hi, I have been trying to create a page where the php sits on the same page as the form it receives data from. I am hoping to the echo out the results to the same page once the php has been run:

I just can't seem to get the code to work:

Code: Select all

 
<?php
if(isset($_POST['submit'])) {
 
$email = $_POST['email'];
 
 
$to = "dstyler@freeuk.com";
$subject = "Newsletter Subscription ";
$message = ("email of sender: ".$email);
$headers = "From:Improvement Associates\r\n";
 
if(mail($to,$subject,$message,$header)) {
$result = "Many thanks for subscribing to our newsletter, you have been added to the mailing list";
} else {
$result = "<h3>Error sending your message.</h3>
        Sorry, an error occured sending.<br />Please try again later or contact us direct to be added to the mailing list";
})
?>
 
<html><body>
              
 <div id="forminp" class="marg">             
<form method="post" action="<? $_SERVER['PHP_SELF']; ?>">
 
 <label for="email">email*</label>
 <input type="text" class="textinput" size="33" tabindex="2" name="email" id="email"/>
 <input id="button" name="submit" type="submit" value="submit" />
 
   </div>
</form>
<?php print $result; ?>
</body>
</html>
Thanks in advance
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: processing a form action in the same page

Post by greyhoundcode »

I suspect you've confused a closing brace } and a closing bracket ).
Post Reply