Question about echo in php code

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
mattdelight
Forum Newbie
Posts: 5
Joined: Sun May 24, 2009 5:54 am

Question about echo in php code

Post 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
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Question about echo in php code

Post 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).
mattdelight
Forum Newbie
Posts: 5
Joined: Sun May 24, 2009 5:54 am

Re: Question about echo in php code

Post 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?
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Question about echo in php code

Post 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.
mattdelight
Forum Newbie
Posts: 5
Joined: Sun May 24, 2009 5:54 am

Re: Question about echo in php code

Post 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.
watson516
Forum Contributor
Posts: 198
Joined: Mon Mar 20, 2006 9:19 pm
Location: Hamilton, Ontario

Re: Question about echo in php code

Post by watson516 »

Your form's action would have to be the file I showed you above.
mattdelight
Forum Newbie
Posts: 5
Joined: Sun May 24, 2009 5:54 am

Re: Question about echo in php code

Post by mattdelight »

Alright I think I know what I need to do.

Most thanks watson!
mattdelight
Forum Newbie
Posts: 5
Joined: Sun May 24, 2009 5:54 am

Re: Question about echo in php code

Post 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
Post Reply