Functions and forms

Just learning about functions and need help understanding this to put it all together. Below is what I have so far.

I created a form and now working on PHP portion. This will return an html web page. I will make it pretty later, just trying to understand this portion. Please look at the comments to understand what each function does. Thank You for any help!

[php]<?php
pagemain();
pageheader();
pagebody();
pagefooter();

//gathers all information and calls all other functions. Not sure how to do this.

function pagemain(){

}

/pageheader will create top html code, including header section.
It will have user write title of page and choose background color
/

function pageheader(){
global $page_Title;
global $HTML;
global $HTML2;
global $bg_Color;

$HTML +="$page_Title";
$HTML2 +=“background-color: $bg_Color>”;

}

//pagebody will have welcome title and welcome statement. Does NOT close body section

function pagebody() {
global $w_Title;
global $statement;
global $HTML;

$HTML +="$w_Title
$statement
";

}
//footer information will have footer and close body section and all other html tags

function pagefooter(){
global $footer;
global $HTML;

$HTML +="";

}

//pulled in from the form

$page_Title = filter_input(INPUT_POST, “page_Title”);
$bg_Color = filter_input(INPUT_POST, “bg_Color”);
$w_Title = filter_input(INPUT_POST, “w_Title”);
$statement = filter_input(INPUT_POST, “statement”);
$footer = filter_input(INPUT_POST, “footer”);

?>
[/php]

I’m really not sure what you are trying to accomplish…

If you want to display the HTML page I think all you need to do is add an

[php]echo HTML; [/php]

to your code

[php] <?php
pagemain();
pageheader();
pagebody();
pagefooter();

echo HTML;

//gathers all information and calls all other functions. Not sure how to do this.

function pagemain(){

}

/pageheader will create top html code, including header section.
It will have user write title of page and choose background color
/

function pageheader(){
global $page_Title;
global $HTML;
global $HTML2;
global $bg_Color;

$HTML +="$page_Title";
$HTML2 +=“background-color: $bg_Color>”;

}

//pagebody will have welcome title and welcome statement. Does NOT close body section

function pagebody() {
global $w_Title;
global $statement;
global $HTML;

$HTML +="$w_Title
$statement
";

}
//footer information will have footer and close body section and all other html tags

function pagefooter(){
global $footer;
global $HTML;

$HTML +="";

}

//pulled in from the form

$page_Title = filter_input(INPUT_POST, “page_Title”);
$bg_Color = filter_input(INPUT_POST, “bg_Color”);
$w_Title = filter_input(INPUT_POST, “w_Title”);
$statement = filter_input(INPUT_POST, “statement”);
$footer = filter_input(INPUT_POST, “footer”);

?>[/php]

I’ve cleaned up my code and changed the $HTML to $PAGE and added the print $PAGE but all it prints is a 0. I’ve been looking at this code so long, maybe some fresh eyes will spot it!

[php]

<?php //gathers all information and calls all other functions function pagemain(){ pageheader(); pagebody(); pagefooter(); } /*pageheader will create top html code, including header section. It will have user write title of page and choose background color*/ function pageheader(){ global $page_Title; global $bg_Color; global $PAGE; $PAGE +="$page_Title background-color: $bg_Color;"; } //pagebody will have welcome title and welcome statement. Does NOT close body section function pagebody() { global $w_Title; global $statement; global $PAGE; $PAGE +="

$w_Title

\n

$statement

"; } //footer information will have footer and close body section and all other html tags function pagefooter(){ global $footer; global $PAGE; $PAGE +="

$footer

"; } //pulled in from the form $page_Title = filter_input(INPUT_POST, "page_Title"); $bg_Color = filter_input(INPUT_POST, "bg_Color"); $w_Title = filter_input(INPUT_POST, "w_Title"); $statement = filter_input(INPUT_POST, "statement"); $footer = filter_input(INPUT_POST, "footer"); pagemain(); print $PAGE; ?>[/php]

I figured it out for you, I take it you’re like me and you have a different development background.

The syntax below is .NET syntax… with the += but in php it should be .= to combine strings.

[php]$PAGE +="$page_Title
background-color: $bg_Color;";[/php]

Like this:

[php]$PAGE .="$page_Title
background-color: $bg_Color;";[/php]

changed to .= and still not working… :frowning:

Change all of them to that… not just the one I posted. Then right click and view source on the page and you will see your html.

Your going about the whole thing the wrong way. You need to include files, not put everything in functions.

[code]
<?php include_once('./includes/header.php'); ?>

     <div id="body">
        <?php include_once('./includes/body.php'); ?>
     </div>

     <div id="footer">
        <?php include_once('./includes/footer.php'); ?>
     </div>[/code]

@ topcoder - Yes I did change all of them to " .=" and viewed my source code and no html just the “0”

@Kevin Rubio - I know your right but I would really like to figure out why this isn’t working first. I’m learning about functions and that’s why they are in the code.

Can you post your changed code please.

Thanks for looking at it again.

[php]<?php

//gathers all information and calls all other functions
function pagemain(){
pageheader();
pagebody();
pagefooter();
}

/pageheader will create top html code, including header section.
It will have user write title of page and choose background color
/
function pageheader(){
global $page_Title;
global $bg_Color;
global $PAGE;

$PAGE .="$page_Title
background-color: $bg_Color;";
}

//pagebody will have welcome title and welcome statement. Does NOT close body section
function pagebody() {
global $w_Title;
global $statement;
global $PAGE;

$PAGE .="

$w_Title

\n

$statement

";
}

//footer information will have footer and close body section and all other html tags
function pagefooter(){
global $footer;
global $PAGE;

$PAGE .="

$footer

";
}

//pulled in from the form
$page_Title = filter_input(INPUT_POST, “page_Title”);
$bg_Color = filter_input(INPUT_POST, “bg_Color”);
$w_Title = filter_input(INPUT_POST, “w_Title”);
$statement = filter_input(INPUT_POST, “statement”);
$footer = filter_input(INPUT_POST, “footer”);

pagemain();
print $PAGE;

?>

[/php]

You need to change all the $PAGE .=
to
echo

Didn’t work and checked page source - no html. :frowning:

I tested your code it works fine for me … when I view the source… I see this…

[php]
background-color: ;

      <p></p><h3></h3></body></html>[/php]

This is not what you might expect to see, but it’s what I expect to see based on the code. But as you can see it doesn’t print a “0”

You can look at your code run here…

http://phphelp.com/phpfunction.php

Right click and view source…

Start from here with basic output from each function.

[php] <?php
function pagemain()
{
pageheader();
pagebody();
pagefooter();
}

function pageheader()
{
echo “Header Output
”;
}

function pagebody()
{

echo "Body Output<br />";
}

function pagefooter()
{

echo "Footer Output";
}

pagemain();
?>[/php]

echo “Header Output
”; prints “Header Output”

Am I misunderstanding you?

No. It was just to display some output from each function. Build on it one step at a time to get what you want.

Sponsor our Newsletter | Privacy Policy | Terms of Service