mthomps71 Posted June 19, 2008 Share Posted June 19, 2008 I'm trying to create a webform in php that will allow a user to add text to various fields and save the text in an html file with a name of their choosing, and I'm stumped. I'm sure I'm complicating it. Below is the frontend I'm struggling with the form processor piece and will forgo even posting any of what I have as it's useless up to this point. I would really like to understand what I need to do, I've looked at fopen and played with trying to get _$POST to allow me to specify the file name being written to but it's not working for me. Any help would be greatly appreciated. <form method="post" action="form.php"> <b>What is the purpose of this service check:<p><textarea name="what" rows="15" cols="60"></textarea><p> Verification steps:<p><textarea name="verification" rows="15" cols="60"></textarea><p> Return to service steps:<p><textarea name="rts" rows="15" cols="60"></textarea><p> Escalation:<p><textarea name="esc" rows="15" cols="60"></textarea><p> Filename:<input type="text" name="file" size="26" maxlength="25" /></b><p> <input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/110953-looking-to-understand/ Share on other sites More sharing options...
trq Posted June 19, 2008 Share Posted June 19, 2008 There is a link in my signiture to a book / wiki. Within that is an entire chapter devoted to handling forms and another dedicated to writting to files. I suggest you take a look. Theres no point us writting you a personal tutorial when there are many, many all ready on the net. Quote Link to comment https://forums.phpfreaks.com/topic/110953-looking-to-understand/#findComment-569225 Share on other sites More sharing options...
mthomps71 Posted June 19, 2008 Author Share Posted June 19, 2008 Thanks I understand RTFM very well and I've done it, hence the post Please delete the post and my account Thanks Quote Link to comment https://forums.phpfreaks.com/topic/110953-looking-to-understand/#findComment-569241 Share on other sites More sharing options...
ober Posted June 19, 2008 Share Posted June 19, 2008 Why don't you post your code and we'll tell you where you've gone wrong? Quote Link to comment https://forums.phpfreaks.com/topic/110953-looking-to-understand/#findComment-569257 Share on other sites More sharing options...
mthomps71 Posted June 19, 2008 Author Share Posted June 19, 2008 There's nothing right about the backend code yet. I'm trying to work with something I found on the web. (I don't know much about php) It's not complete I don't have half of the _$POST variables in yet I'm just stumped on how to create the page from [file] input on the php form. I'm trying to get this done on limited time. It's usage is basically for people within my group here at work who don't html skills. I could tell the to RTFM but everyone has enough to do already. I'm not looking for someone to write the code for me I'm trying to grasp how to fopen a doc that doesn't exist based on what was put into the form and have it dump the rest of the data in the form into said file. <?php $saving = $_REQUEST['saving']; if ($saving == 1) { $data = $_POST['data']; $file = $_POST['file']; $fp = fopen($file, "w") or die("Couldn't open $file for writing!"); fwrite($fp, $data) or die("Couldn't write values to file!"); fclose($fp); echo "Saved to $file successfully!"; } ?> <form name="form1" method="post" action="form.php?saving=1"> <textarea name="file" cols="100" rows="10"> <?php $file = $_POST['file']; if (!empty($file)) { $file = file_get_contents("$file"); echo $file; } ?> </textarea> <br> <input type="submit" value="Save"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/110953-looking-to-understand/#findComment-569311 Share on other sites More sharing options...
mthomps71 Posted June 19, 2008 Author Share Posted June 19, 2008 And I found this which may better suit my needs but I think the part that is stumping me is that all the tutorials I have seen concerning this are writing to a predetermined filename I need to allow the user to specify the filename and for it to be created it if doesn't exist. $info = ""; $info .= "\"$homeowner\","; $info .= "\"$name\","; $info .= "\"$soc1\","; if (!empty($cobwrfull)) { $info .= "\"$cobwrfull\","; $info .= "\"$soc2\","; } else { $info .= "\"\",\"\","; } if (!empty($pmtreq)) { $info .= "\"$pmtreq\","; } else { $info .= "\"\","; } $info .= "\"$company\","; $info .= "\"$yrsempbwr\","; $info .= "\"$cashout\","; $info .= "\"$Calltime\","; $info .= "\"$newNP\""; $info .= "\r\n"; $responseList = "$DOCUMENT_ROOT/formfiles/response.dlm"; $filePointer = fopen($responseList,'a'); fwrite($filePointer, $info); fclose($filePointer); Quote Link to comment https://forums.phpfreaks.com/topic/110953-looking-to-understand/#findComment-569344 Share on other sites More sharing options...
trq Posted June 19, 2008 Share Posted June 19, 2008 Ok, I'm goinjg to simply desregard all your code and write a basic example. <?php if (!isset($_POST['submit'])) { echo "<form action='' method='post'>"; echo " <input type='text' name='filename'> filename?"; echo " <textarea name='data'></textarea>"; echo " <input type='submit' name='submit'>"; echo "</form>"; } else { $file = fopen($_POST['filename'], "w"); fwrite($file,$_POST['data']); fclose($file); } ?> Be aware that if a user chooses the name of a file that already exists it will be overwritten, there is also no security in place to check where they might attempt to write the file to. This really isn'nt the kind of thing you should be attempting to create without at least trying to grasp the basics of php. Letting users write files to your server can be a dangerous bussiness unless you know what your doing. Quote Link to comment https://forums.phpfreaks.com/topic/110953-looking-to-understand/#findComment-569664 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.