|
| Index | Recent Threads | Unanswered Threads | Who's Online | User List | Help |
|
|
| No member browsing this thread |
|
Thread Status: Active Total posts in this thread: 26
|
|
| Author |
|
|
Member Joined: Apr 8, 2008 Post Count: 70 Status: Offline |
Hi, I am trying to figure out how to display a message that indicates that a form has been submitted successfully. I have just one input text field in the top right corner of the page where one can enter their email address to subscribe to a newsletter. Here is the link to the page in progress... http://www.vojodesign.com/proofs/blockedFunds As you can see, I have a background image behind the input box. I would like all of this to disappear and be replaced with some text that just says, "Thank you, you have successfully subscribed to our newsletter!" Can anyone help me code this? I appreciate your time in advance. Kit |
||
|
|
Advanced Member USA Joined: Aug 14, 2007 Post Count: 1129 Status: Offline |
Are you looking for complete PHP code, or just a way to approach it? Here's one way to approach it... <?php if (isset($_GET['success']) == true) { // show success message here } else { // show form here } ?> Basically, this would check the URL for a success message. If the URL would includes "?success", the success message would be shown. If not, the form would be shown. For example: http://www.vojodesign.com/proofs/blockedFunds/ -- doesn't show form http://www.vojodesign.com/proofs/blockedFunds/?success -- shows form http://www.vojodesign.com/proofs/blockedFunds/quote.php?success -- shows form When the form is submitted, it would process the input and then redirect to the same page, with "?success" added to the url. As I said, just one way to approach it. There may be other methods. ---------------------------------------- Benjamin Falk | student : designer : developer Twitter: falkencreative ---------------------------------------- [Edit 1 times, last edit by falkencreative at Dec 8, 2008 2:23:52 AM] |
||
|
|
Member Joined: Apr 8, 2008 Post Count: 70 Status: Offline |
So, would I have to create a version of every page without the form and WITH the success message? |
||
|
|
Advanced Member USA Joined: Aug 14, 2007 Post Count: 1129 Status: Offline |
No, PHP will take care of that for you. Using (roughly) this snippet: <?php if (isset($_GET['success']) == true) { // show success message here } else { // show form here } ?> The browser will figure out if the URL includes the "success" variable, dynamically include or exclude the form. You will only need one version of the page. However, each page would have to use the .php ending, rather than .html, in order for PHP to work (and of course your server will have to support PHP) ---------------------------------------- Benjamin Falk | student : designer : developer Twitter: falkencreative |
||
|
|
Member Joined: Apr 8, 2008 Post Count: 70 Status: Offline |
No, PHP will take care of that for you. Using (roughly) this snippet: <?php if (isset($_GET['success']) == true) { // show success message here } else { // show form here } ?> The browser will figure out if the URL includes the "success" variable, dynamically include or exclude the form. You will only need one version of the page. However, each page would have to use the .php ending, rather than .html, in order for PHP to work (and of course your server will have to support PHP) But since each of the pages that contain the form element have different content, how will the "success" version of the page hold the same content as before the form was sent? |
||
|
|
Advanced Member USA Joined: Aug 14, 2007 Post Count: 1129 Status: Offline |
But since each of the pages that contain the form element have different content, how will the "success" version of the page hold the same content as before the form was sent? I'm not totally sure what you are asking. The only bit of content that changes is whether or not the form displays or not. All the remaining content would stay the same. As I said, when the form is submitted, PHP would be used to process the input and then redirect to exactly the same page, with "?success" added to the url. Since "?success" is part of the URL, PHP would be used to show the success message. A more complete example: <html> <head> </head> <body> Content here... <?php if (isset($_GET['success']) == true) { // show success message here // form will not show } else { // success message will not show // show form here } ?> Content here... </body> </html> ---------------------------------------- Benjamin Falk | student : designer : developer Twitter: falkencreative |
||
|
|
Member Joined: Apr 8, 2008 Post Count: 70 Status: Offline |
But since each of the pages that contain the form element have different content, how will the "success" version of the page hold the same content as before the form was sent? I'm not totally sure what you are asking. The only bit of content that changes is whether or not the form displays or not. All the remaining content would stay the same. As I said, when the form is submitted, PHP would be used to process the input and then redirect to exactly the same page, with "?success" added to the url. Since "?success" is part of the URL, PHP would be used to show the success message. A more complete example: <html> <head> </head> <body> Content here... <?php if (isset($_GET['success']) == true) { // show success message here // form will not show } else { // success message will not show // show form here } ?> Content here... </body> </html> OK. Thanks Falken. I'll give it a go. Kit |
||
|
|
Advanced Member USA Joined: Aug 14, 2007 Post Count: 1129 Status: Offline |
OK, I did a bit of experimenting, and this is what I ended up coming up with... Looks like you really don't need the whole "?success" thing. Just work from this code: <?phpBasically, the if statement just checks if the form has been submitted. If it has, it processes the input, hides the form and prints the right message. If it hasn't been submitted, the form shows. ---------------------------------------- Benjamin Falk | student : designer : developer Twitter: falkencreative |
||
|
|
Member Joined: Apr 8, 2008 Post Count: 70 Status: Offline |
Falken, So I plugged the rest of the code into your recommended code. I have probably totally screwed it up though - i'm terrible with this kind of stuff. Could you see if it looks right to you now? I also pasted below my html. Thanks much. <?php if (isset($_POST['submit'])) { $EmailFrom = "contact@blockedfunds.com"; $EmailTo = "kit@vojodesign.com"; $Subject = "BlockedFunds.com - Contact Form Submission"; $Email = Trim(stripslashes($_POST['Email'])); // prepare email body text $Body .= $Email; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); echo "success"; } else { ?> <form action="" method="post"> <div> <input type="text" name="test" value="" id="test"> <input type="submit" value="submit" name="submit"> </div> </form> <? } ?> HTML... <form action="post" method="../php/newsletterForm.php"> <input id="search_box" onblur="if(this.value==''){this.value='enter your email address...'}" onfocus="this.value=''" title="Enter a keyword and press Enter" value="enter you email address..." size="21" name="s"/> ��������<input name="btnSubscribe" type="button" class="btnSubscribe" id="btnSubscribe" value="Subscribe" /> </form> |
||
|
|
Advanced Member USA Joined: Aug 14, 2007 Post Count: 1129 Status: Offline |
I'll need to take a look at this in more detail later today... I'm just about to leave for work. A couple comments: -- You'll need to integrate your form into my PHP code, removing my form and replacing it with yours -- You'll need to make sure that the names of the form elements match up with the php code. For example, $_POST['email'] is looking for the value of the form element that has the name "email". Same thing with the if statement -- it's looking for a form element with the name of "submit". Currently, neither of your form elements have the name="" property ---------------------------------------- Benjamin Falk | student : designer : developer Twitter: falkencreative |
||
|
|
|
|
|
Current timezone is GMT Mar 21, 2010 11:20:42 AM |