Forum Moderators: coopster

Message Too Old, No Replies

PHP Confirmation Page

         

Unpredict2ble

8:20 am on Dec 19, 2011 (gmt 0)

10+ Year Member



Hello All,

I'm currently learning PHP & MySQL. I do know HTML and CSS.
Anyways, what I want to know is how to format a confirmation page. I'm currently designing a mailing list for a site where the mailing list form resides on the main page, and writes to a mySQL database. Everything works great. The problem is when I hit the join button, the confirmation is a new (_top) window with a plain white background with the 'Thank you for subscribing.' message. I want to format this confirmation page.

How would I go about changing tha plain white window with a small confirmation window(specified height and width, with no scrolling) with my current website color scheme when the user hits the join button?

Thanks for reading.

</Unpredict2ble>

lostdreamer

9:59 am on Dec 19, 2011 (gmt 0)

10+ Year Member



The most logical way would be to use some kind of template system... You can use an existing, or create your own, it's pretty easy.

What I used to do a lot in the days I started PHP was to use the Output Buffer functions of PHP in combination with an included file (layout.php) for the whole website.

Something like this:

config.php:
- Has a link to the DB, some standard variabels get declared here etc.
- It also uses ob_start() to start an output buffer
( [php.net...] )

form.php
- includes config.php
- echo's the HTML for a form
- includes layout.php

layout.php
- starts with

$html = ob_get_clean();

- Then you echo the complete HTML for your template with the variable $html where you want your content.

ie:

<html>
<head>
<title>Test</title>
</head>
<body>
<div id="content">
<?php
echo $html;
?>
</div>
</body>
</html>



Good luck,
LostDreamer

Unpredict2ble

4:00 pm on Dec 19, 2011 (gmt 0)

10+ Year Member



I can grasp the concept of what you're saying, but being that I'm new to PHP/MySQL, I've yet to cross alot of what you posted. Like I said, I do understand the concept, and therefore I may be able to figure it out.

1 thing that you posted that I really don't understand is how I would assign a layout to a variable. You used $html. How would I assign a whole page to $html?

I'm not sure how to use HTML tags inside PHP. Is code like the following valid?


<?php

echo <html>
echo <head><title>....</title></head>
echo <body>....</body>
echo </html>

?>


</Unpredict2ble>

rocknbil

4:48 pm on Dec 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, a better way might be something like this.

<?php
// store the result of the function "compose_message()"
// in the variables $title and $msg
list ($title,$msg) = compose_message();
?><html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1><?php echo $title; ?></h1>

<?php echo $msg; ?>

</body>
</html>

<?php
// The function can be located anywhere
// in the document. In this example, the function
// returns two values in an array: title and message

function compose_msg() {
$ttl = 'This is my title';
$message= '<p>Thank you for your interest.</p>';
return array ($ttl,$message);
}

?>
(This code **should** run if you want to drop it in a PHP file and test it.)

See how it drops "in and out" of PHP? I use a function there to group the programming in one place, too often PHP documents are a long series of in and out PHP, it becomes very hard to follow and maintain (called "spaghetti code.") By putting your message composition in a function, it minimizes this and allows you to move it around where you want - like, in an include, for example

<?php
// here the call to compose_message and
// the function itself are stored in an
// external file
include('compose-message.php');
?><html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1><?php echo $title; ?></h1>

<?php echo $msg; ?>

</body>
</html>

Look how neat and easy that is to understand. :-) A templating system is by far a better choice, but for a simple one-off document, this approach will teach you a couple things and build your knowledge of PHP - you can expand later into templates after your feet are wet.

Unpredict2ble

10:40 pm on Dec 19, 2011 (gmt 0)

10+ Year Member



I do see how you're dropping in and out of PHP. I'll remember that. Thanks for sharing. I didn't see how to create a new browser window with a specific height, width, color scheme, and not scrollable.

If you want to view the page I'm designing and coding, visit:
[symphonirose.com ](under construction).

If you join the Newsletter, you'll see the confirmation page I'm talking about. I want the color scheme to match my site, and then pop-up in a small window so as to not cover my entire site like it does now.

</Unpredict2ble>

rocknbil

5:03 pm on Dec 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Re-read the TOS [webmasterworld.com] in respect to personal site links, just FYI. WebmasterWorld is a bit different than most message boards.

I didn't see how to create a new browser window with a specific height, width, color scheme, and not scrollable.


That's really more of a Javascript question - but making a window not scrollable or resizable is a really.bad.idea. Why? Although you test until you're seeing double, you'll never know your end user's environment. I've seen too many sites with this concept in place, and I can't scroll down to the rest of the content or a submit button. X button = epic fail. :-)

Some info on opening new windows [webmasterworld.com]

There are many such posts here . . . as for styling and formatting, treat your output like any other HTML page, answers for that can be found in the CSS forum.

Unpredict2ble

5:51 pm on Dec 20, 2011 (gmt 0)

10+ Year Member



I've since changed angles. I'm now trying to get PHP to stay on the main page after the form info is submitted. I did end up tapping into javascript for help with opening the new browser, and I styled it using CSS.

Being that it was a PHP page, It threw me off a bit to where I didn't realize I could still style it as normal. My problem now is, it opens the new javscript pop up window, AND it still show the 'confirmation page' as well.

</Unpredict2ble>

rocknbil

5:24 pm on Dec 21, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



opens the new javscript pop up window, AND it still show the 'confirmation page' as well.


Because, most likely, you're not using return false correctly. Personally I think a confirmation in a new window is not needed, but let's roll with it.

In Javascript, return false stops any normal reaction by the browser. It can go on a link, a form, a button, anything that accepts user events. So when you do this,

<a href="mycontent.html" onclick="newWindow('my-content.html'); return false;">My Content</a>

It will open mycontent.html and the originating page (called the window.opener) will not navigate to mycontent.html. Note the "regular link" in href - this is important. If Javascript is disabled, users can still access your content.

The same is true of forms. You have to somehow target the form to a new window, but return false in the window.opener. How you'd do that depends on how you have your new window set up. It should look **something** like this . . .

<form method="post" action="post-location.php" onsubmit="newWindow('post-location.php'); return false;">

A caveat, generally you'd just return false from your function,

function newWindow() {
// do whatever
return false;
}

Then you can express your links/forms like so


<a href="mycontent.html" onclick="return newWindow('my-content.html');">My Content</a>

<form method="post" action="post-location.php" onsubmit="return newWindow('post-location.php');">