Trium918 Posted March 22, 2007 Share Posted March 22, 2007 I have two problems with this code. The first problem is getting to program to validate the form to see if the user enter data into the <textarea></textarea> because without it, the use is able to click the submit button and a blank line is inserted. I donnot want that, but instead promt the user to enter data. A new line is insert when someone refresh the page. I donnot want that. The second problem is that I tried to create one myself but it exited out because I called the exit; command. I commented it out and refreshed the page and it still echo "There was no data entered!!"; . Some how it stayed in memory even after I cleared history and deleted cookies. I had to rename the php file in order to get it to show in the browse. Why does it do that and how to fix it? Both of these links have the same code that I provided below!! Example: of echo "There was no data entered!!"; Example: of how validation help <? /*if(!isset($content)) { echo "There was no data entered!!"; //exit; }*/ ?> <form method="POST"> <table border="1" align="center" width="300"> <tr><td colspan="2" align="center">How to Change the World?</td></tr> <tr> <td align="center"><img src="../images/atlas.jpg" width="100" height="165" /></td> <td ><textarea name = "content" cols="50" rows="10"></textarea></td> </tr> <tr><td colspan="2" > <? $content = $_POST['content']; $info = $_POST['info']; @$fp = fopen("project4.txt", "a"); fwrite($fp, $content."\r\n"); $info = file('project4.txt'); for ($i = 0; $i < count($info); $i++) { echo '<br><hr>'; echo nl2br(htmlentities(stripslashes(trim($info[$i])),ENT_QUOTES)); } fclose($fp); ?> </td></tr> <tr><td colspan="2" align="center"><input type = submit name="submit"></td></tr> </form> Link to comment https://forums.phpfreaks.com/topic/43879-solved-validation-help/ Share on other sites More sharing options...
Psycho Posted March 22, 2007 Share Posted March 22, 2007 <? if(isset($_POST)) { //Page was submitted if (!$_POST['content']) { //value of content is empty $output = "There was no data entered!"; } else { //Content has value $content = $_POST['content']; $info = $_POST['info']; @$fp = fopen("project4.txt", "a"); fwrite($fp, $content."\r\n"); $info = file('project4.txt'); for ($i = 0; $i < count($info); $i++) { $output = '<br><hr>'; $output .= nl2br(htmlentities(stripslashes(trim($info[$i])),ENT_QUOTES)); } fclose($fp); } } ?> <form method="POST"> <table border="1" align="center" width="300"> <tr> <td colspan="2" align="center">How to Change the World?</td> </tr> <tr> <td align="center"><img src="../images/atlas.jpg" width="100" height="165" /></td> <td><textarea name = "content" cols="50" rows="10"></textarea></td> </tr> <tr> <td colspan="2"><?=$output?></td> </tr> <tr> <td colspan="2" align="center"><input type = submit name="submit"></td> </tr> </table> </form> Link to comment https://forums.phpfreaks.com/topic/43879-solved-validation-help/#findComment-213035 Share on other sites More sharing options...
Trium918 Posted March 22, 2007 Author Share Posted March 22, 2007 Read the code and click on the links that I provided above. I tried out mjdamato code but it's not reading the entire file It only displaynig one line at a time. I would like to display previous entries. Link to comment https://forums.phpfreaks.com/topic/43879-solved-validation-help/#findComment-213064 Share on other sites More sharing options...
Psycho Posted March 23, 2007 Share Posted March 23, 2007 Well, you marked this thread as completed, but your last response sounds as if that's not the case. And your links above seem to have working pages now (except one possible issue). So, I'm not sure how to respond. The one "issue" that i see is that the previous responses are not displayed until the user enters their response. This may be by design. And, if the user doesn't enter data the responses (if displayed) dissapear. You might want to try out this code: <?php if (isset($_POST) && !$_POST['content']) { //value of content is empty $error = '<span style="color:red;">There was no data entered!</span>'; } else { $error = ''; } @$fp = fopen("project4.txt", "a"); if ($_POST['content']) { $content = $_POST['content']; $info = $_POST['info']; fwrite($fp, $content."\r\n"); } $info = file('project4.txt'); for ($i = 0; $i < count($info); $i++) { $output = '<br><hr>'; $output .= nl2br(htmlentities(stripslashes(trim($info[$i])),ENT_QUOTES)); } fclose($fp); ?> <form method="POST"> <table border="1" align="center" width="300"> <tr> <td colspan="2" align="center">How to Change the World?</td> </tr> <tr> <td align="center"><img src="../images/atlas.jpg" width="100" height="165" /></td> <td><textarea name = "content" cols="50" rows="10"></textarea></td> </tr> <tr> <td colspan="2"><?=$error?></td> </tr> <tr> <td colspan="2"><?=$output?></td> </tr> <tr> <td colspan="2" align="center"><input type = submit name="submit"></td> </tr> </table> </form> Link to comment https://forums.phpfreaks.com/topic/43879-solved-validation-help/#findComment-213147 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.