a function return + variable to exit

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
NAT
Forum Newbie
Posts: 24
Joined: Tue Mar 21, 2006 3:13 am

a function return + variable to exit

Post by NAT »

Hi,


I made a simple mailform script, where users can send email to me. Now i want to make a message, so when they submit the form that the form desapears and they get a message <span style='color:red;text-decoration:blink' title='Alert a moderator!'>grilled spam</span>:

echo "Your mail has been submited" . So that they only c the text message "Your mail is submited" .

I know it must be done with some function and with combination of a variable :? but i am not shote of it.


Can anyone explain how can i do this?


Thanks in advance,

NAT
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

<?php
if(!empty($_POST)){
   //  send email
   echo "Your email message has been submitted.";
} ELSE {
   echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">";
   // rest of form here
}
?>
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
NAT
Forum Newbie
Posts: 24
Joined: Tue Mar 21, 2006 3:13 am

Post by NAT »

But there is also other way. I think with function return and then you have to make a variable wich listens to that function, foreaxample like this:

$thisvariable = $resturn; $i

//herecomes a form

echo "your post is submitted"

echo = $thisvariable


:? :? :? :? :? is this possible?
NAT
Forum Newbie
Posts: 24
Joined: Tue Mar 21, 2006 3:13 am

Post by NAT »

I tryd this code, but the form is not desapearing. it gives the message after submitting the form "you remail has been submited" but the form is not desapearing. :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

did you put the form inside the "else" block?
NAT
Forum Newbie
Posts: 24
Joined: Tue Mar 21, 2006 3:13 am

Post by NAT »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Sry for late answer, i have almost no time after work     

But this how i wrote the script and add it also the one that posted [b]scottay[/b]

Code: Select all

<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">
<strong>				
Name:</strong>&nbsp;
			
<input type="text" name="sender_name" style="width:150px; height:17px; font-family:Tahoma; font-size:10px; border-width:1px; border-style:solid; border-color:#667079  ">
<br><img src="images/spacer.gif" height="5px"><br>
<strong>	
Email:</strong>&nbsp;
<input type="text" name="sender_email" style="width:150px; height:17px; font-family:Tahoma; font-size:10px; border-width:1px; border-style:solid; border-color:#667079  ">
<br><img src="images/spacer.gif" height="5px"><br>
<strong>
Message:
</strong>	
<br><img src="images/spacer.gif" height="3px"><br>
<textarea name="message" style="width:320px; height:120px; font-family:Tahoma; overflow:auto; font-size:10px; border-width:1px; border-style:solid; border-color:#667079;  "></textarea>
<div style="padding-top:5px;padding-right:45px " align="center"><input type="image" src="images/submit.jpg"> </div>

</form>


</TD>
</TABLE>

<?php 
if(!empty($_POST)){ 

echo "Your email message has been submitted."; 

} else { 

echo "<form action=\"{$_SERVER['PHP_POST']}\" method=\"post\">"; 

} 


$msg = "E-MAIL WAS SEND FROM WEBSITE\n";

$msg .= "E-Mail:\t$_POST[sender_email]\n";

$msg .= "Message:\t$_POST[message]\n";
$to = "xxxxx@xxxx.com";
$subject = "Web Site Feedback";
$mailheaders .= "Reply-To: $_POST[sender_email]\n";
$mailsend = mail($to, $subject, $msg, $mailheaders);


?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Nathaniel
Forum Contributor
Posts: 396
Joined: Wed Aug 31, 2005 5:58 pm
Location: Arkansas, USA

Post by Nathaniel »

No, you want something like this:

Code: Select all

<?php 
if(!empty($_POST)){ 

echo "Your email message has been submitted."; 

$msg = "E-MAIL WAS SEND FROM WEBSITE\n";
$msg .= "E-Mail:\t$_POST[sender_email]\n";
$msg .= "Message:\t$_POST[message]\n";

$to = "xxxxx@xxxx.com";
$subject = "Web Site Feedback";
$mailheaders = "Reply-To: $_POST[sender_email]\n";
$mailsend = mail($to, $subject, $msg, $mailheaders);

} else { 
?>
<form action="{$_SERVER['PHP_SELF']}\" method=\"post\">
<strong>                
Name:</strong>&nbsp;
            
<input type="text" name="sender_name" style="width:150px; height:17px; font-family:Tahoma; font-size:10px; border-width:1px; border-style:solid; border-color:#667079  ">
<br><img src="images/spacer.gif" height="5px"><br>
<strong>    
Email:</strong>&nbsp;
<input type="text" name="sender_email" style="width:150px; height:17px; font-family:Tahoma; font-size:10px; border-width:1px; border-style:solid; border-color:#667079  ">
<br><img src="images/spacer.gif" height="5px"><br>
<strong>
Message:
</strong>    
<br><img src="images/spacer.gif" height="3px"><br>
<textarea name="message" style="width:320px; height:120px; font-family:Tahoma; overflow:auto; font-size:10px; border-width:1px; border-style:solid; border-color:#667079;  "></textarea>
<div style="padding-top:5px;padding-right:45px " align="center"><input type="image" src="images/submit.jpg"> </div>

</form> 
<?PHP
}
?>
NAT
Forum Newbie
Posts: 24
Joined: Tue Mar 21, 2006 3:13 am

Post by NAT »

Yep that works, thanks.
Post Reply