ccerame Posted June 14, 2012 Share Posted June 14, 2012 Goal: Have a form on an html page generate a new page using php once the form is submitted. I've been working on this project for over a week now, and can't seem to get the functionality I want. I'm not very familier with php, I'm usually a MATLAB or python programmer, so I've been gleaning what I can from other people's questions and solutions that worked for them. This is my main page: <!DOCTYPE html> <html> <body> <link rel="stylesheet" type="type/css" href="vytran_css.css" /> <head New Product Introduction <title> Start </title> </head <p> In order to begin the process of introducing a new product, please complete the following form. Once you are satisfied with your responses to the various prompts, please click on the submit button at the bottom of the page. If you would like to start over, click the Reset button. If you have any questions, Please follow the link that says "Help". <form action="create_file.php" method="post" name="form1"> <input type="text" name="new_project"> <br> Product Name: <input name="Name" size="20" type="text"> <br><br> Project Lead Name: <input name="PLname" size="20" type="text"> <br><br> Team-members: <br> <textarea name="Team_members" rows=10 cols=40> </textarea> <br><br> Product Type: <br> <input name="Product_Type" size="20" type="text"> <br><br> Description: <br> <textarea name="Description" rows=10 cols=40 type="text"> </textarea> <br> <br> <br> <input value="Submit" type="submit" name="formSubmit"> <input value="Reset" type="reset"> <input value="Help" type="button" onclick="window.location.href='problems.html'"> </form> </p> </body> </html> and this is the php I have right now: <?php ob_start(); $Name = @$_POST['Name']; ?> <html> <body> <p> Product Name: <?php echo $Name; ?> <br> Project Lead: <?php echo $PLname; ?> <br> Team Members: <?php echo $Team_members; ?> <br> <br> Product Type: <?php echo $Product_type; ?> <br> Description: <?php echo $Description; ?> </p> </body> </html> <?php $output = ob_get_contents(); $newfile="newPage.htm"; $file = fopen ($newfile, "w"); fwrite($file, $output); fclose ($file); ob_end_clean(); echo $output; ?> Please help me get this working. -C Quote Link to comment Share on other sites More sharing options...
Jessica Posted June 14, 2012 Share Posted June 14, 2012 1. Don't surpress errors (@) 2. Is error reporting turned on and set to E_ALL Quote Link to comment Share on other sites More sharing options...
ccerame Posted June 14, 2012 Author Share Posted June 14, 2012 Okay, I just changed that. The page now generates, but none of the data transfers to the page. :/ Quote Link to comment Share on other sites More sharing options...
Jessica Posted June 14, 2012 Share Posted June 14, 2012 Try putting all of the text into a string, then you can write the string to the file and output it, rather than using ob_get_contents(); I don't know if ob_get_contents will work for html that is not echo'd by PHP? Maybe not? Also $Name is the only one you've defined. If error reporting is indeed on, you'll get many notices about your script. Quote Link to comment Share on other sites More sharing options...
ccerame Posted June 14, 2012 Author Share Posted June 14, 2012 So, something like: $output = file_put_contents($Name, $PLname, $Team_members, $Product_type, $Description); Quote Link to comment Share on other sites More sharing options...
scootstah Posted June 14, 2012 Share Posted June 14, 2012 So, something like: $output = file_put_contents($Name, $PLname, $Team_members, $Product_type, $Description); No, something like: $html = <<<HEREDOC Product Name: $Name <br> Project Lead: $PLname <br> Team Members: $Team_members <br> <br> Product Type: $Product_type <br> Description: $Description HEREDOC; file_put_contents('newPage.htm', $html); I don't know if ob_get_contents will work for html that is not echo'd by PHP? Maybe not? Something has to be output to use output buffering. Quote Link to comment Share on other sites More sharing options...
ccerame Posted June 14, 2012 Author Share Posted June 14, 2012 So: <?php error_reporting(E_ALL); ob_start(); $Name = $_POST['Name']; $PLname= $_POST['PLname']; $Team_members= $_POST['Team_members]; $Product_type= $_POST['Product_type']; $Description= $_POST['Description']; ?> <html> <body> </body> </html> <?php $html = <<<HEREDOC Product Name: $Name <br> Project Lead: $PLname <br> Team Members: $Team_members <br> <br> Product Type: $Product_type <br> Description: $Description HEREDOC; file_put_contents('newPage.htm', $html); echo $html; ?> ? (I apologize for not understanding :/. This isn't what I'm' used to.) Quote Link to comment Share on other sites More sharing options...
scootstah Posted June 14, 2012 Share Posted June 14, 2012 You don't have to echo $html. The file_put_contents() function will create the HTML page like you wanted. Quote Link to comment Share on other sites More sharing options...
ccerame Posted June 14, 2012 Author Share Posted June 14, 2012 Okay. Is there any way to get it to immediately take the user to the newly created page? Quote Link to comment Share on other sites More sharing options...
scootstah Posted June 14, 2012 Share Posted June 14, 2012 Sure, you can use a header() redirect. header('location: newPage.html'); Quote Link to comment Share on other sites More sharing options...
ccerame Posted June 14, 2012 Author Share Posted June 14, 2012 It's still not rendering correctly...I attached what the screen looks like after I submit the form and it takes me to the new page. Here is my form page: <!DOCTYPE html> <html> <body> <link rel="stylesheet" type="type/css" href="vytran_css.css" /> <head New Product Introduction <title> Start </title> </head <p> In order to begin the process of introducing a new product, please complete the following form. Once you are satisfied with your responses to the various prompts, please click on the submit button at the bottom of the page. If you would like to start over, click the Reset button. If you have any questions, Please follow the link that says "Help". <form action="htmlData.php" method="post"> Product Name: <input name="Name" size="20" type="text"> <br><br> Project Lead Name: <input name="PLname" size="20" type="text"> <br><br> Team-members: <br> <textarea name="Team_members" rows=10 cols=40> </textarea> <br><br> Product Type: <br> <input name="Product_Type" size="20" type="text"> <br><br> Description: <br> <textarea name="Description" rows=10 cols=40 type="text"> </textarea> <br> <br> <br> <input value="Submit" type="submit" name="formSubmit"> <input value="Reset" type="reset"> <input value="Help" type="button" onclick="window.location.href='problems.html'"> </form> </p> </body> </html> And the php file: <?php error_reporting(E_ALL); ob_start(); $Name = $_POST['Name']; $PLname= $_POST['PLname']; $Team_members= $_POST['Team_members]; $Product_type= $_POST['Product_type']; $Description= $_POST['Description']; $html = <<<HEREDOC Product Name: $Name <br> Project Lead: $PLname <br> Team Members: $Team_members <br> <br> Product Type: $Product_type <br> Description: $Description HEREDOC; file_put_contents('newPage.htm', $html); header()redirect.header('location: newPage.html') ?> Quote Link to comment Share on other sites More sharing options...
ZulfadlyAshBurn Posted June 14, 2012 Share Posted June 14, 2012 you've forgotten to add single quote to the end of $Team_members= $_POST['Team_members]; change it to $Team_members= $_POST['Team_members']; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.