Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Basic PHP Website (2018) Adding a Basic Form Redirecting After a Form Submission

Vladislav Mavrin
PRO
Vladislav Mavrin
Pro Student 3,125 Points

thanks.php is a blank page

Hi

after submitting the form I am redirected, but thanks.php turns out to be a blank page. I checked its code and it seems OK to me. Would appreciate your help, thanks thanks.php

<?php
$pageTitle = "Thank you";
$section = null;
include ("inc/header.php");

?>


<div class="section page">
    <h1>Your suggestion</h1>
    <p>Thanks for the email! I&rsquo;ll check out your suggestion!</p>
</div>

<?php
include ("inc/footer.php");
?>

Hi,

I don't have answer you're looking for but thought it worth mentioning that I just replaced the contents of my local thanks.php file with your code and the redirect page displayed correctly - so it may not be an issue with the snippet above. Were you able to see the correct url, header and/or footer and was the redirect call in process.php ok?

Vladislav Mavrin
Vladislav Mavrin
Pro Student 3,125 Points

Hi Clare, suggest.php looks just fine, the I submit the form and get redirected to the blank thanks.php

here are my codes for process.php and suggest.php suggest.php

<?php 
$pageTitle = "Suggest a media item";
$section = "suggest";
include ("inc/header.php"); ?>
<div class="section page">
    <div class="wrapper">
<h1>Suggest a media item</h1>
<p>If you think smth is missing</p>
<form method="post" action="process.php">
    <table>
        <tr>
            <th>
                <label for="name">Name</label>
            </th>
            <td>
                <input type="text" id="name "name="name" />
            </td>
        </tr>
        <tr>
            <th>
                <label for="email">Email</label>
            </th>
            <td>
                <input type="text" id="email "name="email" />
            </td>
        </tr>
        <tr>
            <th>
                <label for="details">Suggest Item Details</label>
            </th>
            <td>
                <textarea id="details "name="details"></textarea>
            </td>
        </tr>
    </table>
    <input type="submit" value="Send">

</form>
</div>
</div>
<?php include ("inc/footer.php"); ?>

process.php

<?php
$name = $_POST["name"];
$email = $_POST["email"];
$details = $_POST["details"];
echo "<pre>";
$email_body = "";
$email_body .= "Name " . $name . "\n";
$email_body .=  "Email " . $email . "\n";
$email_body .=  "Details " . $details . "\n";
echo $email_body;
echo "</pre>";
//To do: Send email
header ("location:thanks.php");
?>

Also, If I move thanks.php code to process.php, process.php is displayed correctly alt text

1 Answer

Vladislav Mavrin
PRO
Vladislav Mavrin
Pro Student 3,125 Points

Suddenly thanks.php started to work. Have not changed anything. Probably there was some stuff going on on my server.

Good to hear!