Page 1 of 1

Question about echo in php code

Posted: Sun May 24, 2009 6:10 am
by mattdelight
Hey guys and gals. I'm new to php so I'm working with a very basic template for making a contact form for my site. The html is solid I just had a question about the echo aspect of the php code i'm working with. I wanted to know if it was possible for the "message success" or "message fail" window that pops up after you click submit can be on a custom page instead of just displaying on a blank one.

This is what I'm working with

Image

I'm not sure if I'm even explaining it correctly. I've been up all night on google trying to solve the problem for myself. Any help would be greatly appreciated.

Matt

Re: Question about echo in php code

Posted: Sun May 24, 2009 8:16 am
by watson516
If you want to display the success/fail message on your site's template, you need to add the template data (html tags) to your success/fail statement.

It might be easier to either create a seperate page or use the contact form itself. If you use the contact form, you could check (before displaying the contact form) to see if it has been submitted. If it has, display the message instead of the contact form. If it hasn't, display the contact form. You could check to see if it has been submitted by checking for the POST data. If it exists, the form has been submitted (providing your form uses POST).

Re: Question about echo in php code

Posted: Sun May 24, 2009 8:21 am
by mattdelight
I guess my question is what tags and where do I add them?

I just want to use my own sites html template so instead of the "your message has been successful" showing up on a new blank page, what exactly do I have to input into the .php in order to direct it there?

Re: Question about echo in php code

Posted: Sun May 24, 2009 8:28 am
by watson516
Ok...

If you want to use a separate file from your contact form, you could do something like...

Code: Select all

<?php
//Check to see if the contact form was submitted and then check to see if everything worked out right
include_once('includes/header.php');
if($success) {
    echo '<h1>Success!</h1><p>Your message has been submitted</p>';
}else{
    echo '<h1>Error</h1><p>There was an error while submitting the contact form. <a href="contact.php" title="Contact">Please try again.</a></p>';
}
include_once('includes/footer.php');
?>
...or something like that.

Re: Question about echo in php code

Posted: Sun May 24, 2009 8:35 am
by mattdelight
will placing, say, success.html in the < a href > section direct the success message to that .html?

Sorry, bare with me. I'm trying to learn how to build a site from scratch.

If you'd like, pm me and I'll send you a link to the feedback.html of my site so you can get an idea of what I'd like to do.

Re: Question about echo in php code

Posted: Sun May 24, 2009 8:39 am
by watson516
Your form's action would have to be the file I showed you above.

Re: Question about echo in php code

Posted: Sun May 24, 2009 8:42 am
by mattdelight
Alright I think I know what I need to do.

Most thanks watson!

Re: Question about echo in php code

Posted: Mon May 25, 2009 9:27 am
by mattdelight
For anyone who stumbles into this thread experiencing the same problem:

This is how I solved it:

http://php.about.com/od/learnphp/qt/php_with_html.htm