JasperHope Posted April 18, 2010 Share Posted April 18, 2010 I've been trying to do this for about three hours. I'm seriously close to throwing my PC screen though the window. I need to tell PHP to write some text to a .txt file. Here's the PHP: $content = $_POST["rte1"]; $file = "../blog/file.txt"; $Saved_File = fopen($file, 'w'); fwrite($Saved_File, $content); fclose($file); Here's HTML that works with it: <form action="../blog/save.php" method="POST"> <textarea name="rte1"></textarea> <br> <input type="submit" value="Save"> </form> Now, I want the same thing to happen, but instead with this: <form action="../blog/save.php" method="POST"> <div align="center"> <script language="JavaScript" type="text/javascript"> <!-- function submitForm() { //make sure hidden and iframe values are in sync for all rtes before submitting form updateRTEs(); //change the following line to true to submit form alert("rte1 = " + (document.RTEDemo.rte1.value)); return false; } //Usage: initRTE(imagesPath, includesPath, cssFile, genXHTML, encHTML) initRTE("../cbrte/images/", "../cbrte/", "", true); //--> </script> <noscript> <p><b>Javascript must be enabled to use this form.</b></p> </noscript> <script language="JavaScript" type="text/javascript"> <!-- //build new richTextEditor var rte1 = new richTextEditor('rte1'); rte1.html = 'here's the "\<em\>preloaded\<\/em\> \<b\>content\<\/b\>"'; //enable all commands for demo rte1.cmdFormatBlock = true; rte1.cmdFontName = true; rte1.cmdFontSize = true; rte1.cmdIncreaseFontSize = true; rte1.cmdDecreaseFontSize = true; rte1.cmdBold = true; rte1.cmdItalic = true; rte1.cmdUnderline = true; rte1.cmdStrikethrough = true; rte1.cmdSuperscript = true; rte1.cmdSubscript = true; rte1.cmdJustifyLeft = true; rte1.cmdJustifyCenter = true; rte1.cmdJustifyRight = true; rte1.cmdJustifyFull = true; rte1.cmdInsertHorizontalRule = true; rte1.cmdInsertOrderedList = true; rte1.cmdInsertUnorderedList = true; rte1.cmdOutdent = true; rte1.cmdIndent = true; rte1.cmdForeColor = true; rte1.cmdHiliteColor = true; rte1.cmdInsertLink = true; rte1.cmdInsertImage = true; rte1.cmdInsertSpecialChars = true; rte1.cmdInsertTable = true; rte1.cmdSpellcheck = true; rte1.cmdCut = true; rte1.cmdCopy = true; rte1.cmdPaste = true; rte1.cmdUndo = true; rte1.cmdRedo = true; rte1.cmdRemoveFormat = true; rte1.cmdUnlink = true; rte1.toggleSrc = true; rte1.build(); //--> </script> </div> <p align="center">Click submit to complete the update.</p> <p align="center"><input type="submit" name="submit" value="Submit" /></p> </form> I need to grab this from the above code: alert("rte1 = " + (document.RTEDemo.rte1.value)); Because I believe that is what stores the textbox data. But how? How do I take the content of (document.RTEDemo.rte1.value) and send it to a .txt file? Quote Link to comment https://forums.phpfreaks.com/topic/198922-html-javascript-to-php-seriously-urgent/ Share on other sites More sharing options...
PC Nerd Posted April 18, 2010 Share Posted April 18, 2010 Hi, It's hard to say what your rtel.build() function does, but you might want to check that its building the hidden field containing the value you want. The only way to send a javascript variable to php is to have a hidden text field --> <input type="hidden" name="rtel" value="whatever" /> So when you have finished your javascript ( pressumably somewhere around the build(), depending on what it does) you will want to do something like: document.forms[0].rtel.value=retl; this makes a few assumptions that a) you have only one form ( perhaps add a name="myform" attroibute to the form and access it that way), and that you have already created the empty hidden field. When you get to php, you will have the hidden field jsut like any other text field, in $_REQUEST or $_POST etc. Good luck! P.S. - It usually doesnt help to post "urgent" etc. in the thread topic. Quote Link to comment https://forums.phpfreaks.com/topic/198922-html-javascript-to-php-seriously-urgent/#findComment-1044156 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.