0

I'm trying to make it so that every time the person presses the submit button, a txt file will be created containing the information on the textboxes. After the form is submitted, it redirects to a different html file. But this does not work

THIS IS MY PHP CODE (File name:process.php)

<?php
                    $form = fopen("forms/openhouse_signup.txt", "w") or die("Error: Missing Forms on Server!");
                    if (!empty($_POST)){
                        $txt = "Parent's Name: ".$_POST['parentN']."\n";
                        fwrite($form, $txt);

                        $txt = "Email Address: ".$_POST['email']."\n";
                        fwrite($form, $txt);

                        $txt = "Postal Code: ".$_POST['postal']."\n";
                        fwrite($form, $txt);

                        $txt = "Phone Number: ".$_POST['phone']."\n";
                        fwrite($form, $txt);

                        $txt = "Child's Name: ".$_POST['childN']."\n";
                        fwrite($form, $txt);

                        $txt = "Child's Age: ".$_POST['childA']."\n";
                        fwrite($form, $txt);

                        $txt = "\n ----------------------------- \n";
                        fwrite($form, $txt);

                        fclose($form);
                        header('Location: done.html');
                    }
?>

MY HTML CODE (File Name:signup.html)

<h2 style="font-family:Arial, Sans-serif">Please Fill In The Following Boxes To Sign Up</h2>
                <form style="font-family:Arial, sans-serif; font-size:12pt" name="input" action="process.php" method="POST">
                    Full Name of Parent:<br> 
                    <input class="txtbox" type="text" name="parentN"><br><br>
                    Email Address:<br> 
                    <input class="txtbox" type="text" name="email"><br><br>
                    Postal Code:<br> 
                    <input class="txtbox" type="text" name="postal"><br><br>
                    Phone Number:<br> 
                    <input class="txtbox" type="text" name="phone"><br><br>
                    Full Name of Child:<br> 
                    <input class="txtbox" type="text" name="childN"><br><br>
                    Age of Child:<br> 
                    <input class="txtbox" type="text" name="childA"><br><br>
                    <input type="submit" value="Sign Up!">
                </form>
1
  • That's a poor validity check, just testing for if(!empty($_POST)). What if the user creates Elements using firebug, or something? Just a comment. Commented Jul 20, 2014 at 5:19

2 Answers 2

1

I have tested your code and it is working perfectly. So so far so good, then I have found this issue that I think is yours. You may not have the rights to open and to write inside a file. To fix this you need to change its chmod to 777. You can do it either by a command line:

chmod 777 filename.php

or a PHP instruction if you prefer:

chmod(filename.php, 777);

Also chmod to 777 the form folder to be able to create anything inside this folder.

Then I've ran again the code and it worked perfectly. Here is the output from the .txt file:

Parent's Name: a
Email Address: b
Postal Code: c
Phone Number: de
Child's Name: e
Child's Age: f

 ----------------------------- 

For more documentation on chmod see : http://php.net//manual/fr/function.chmod.php and http://en.wikipedia.org/wiki/Chmod

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, this is probably why. I will fix it right now. Thanks for your help!
0

Try after adding 'value' attribute in text-field as following :

   <form name="input" action="process.php" method="POST">
            Full Name of Parent:<br> 
            <input class="txtbox" type="text" value="" name="parentN"><br><br>
            Email Address:<br> 
            <input class="txtbox" type="text" value="" name="email"><br><br>
            Postal Code:<br> 
            <input class="txtbox" type="text" value="" name="postal"><br><br>
            Phone Number:<br> 
            <input class="txtbox" type="text" value="" name="phone"><br><br>
            Full Name of Child:<br> 
            <input class="txtbox" type="text" value="" name="childN"><br><br>
            Age of Child:<br> 
            <input class="txtbox" type="text" value="" name="childA"><br><br>
            <input type="submit" value="Sign Up!">
        </form>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.