andrewgarn Posted May 30, 2008 Share Posted May 30, 2008 I have seen this feature in pages before, you click an EDIT link and the text becomes editable with a save option. (like a wiki) How is this done? I've done some research and there are some content management systems that will do it, but I just want a simple page I can make myself. The editing would preferably allow simple html like <b> and <p> If user logged in -> show edit links in appropriate areas. If not -> just show text Click edit -> text becomes editable options -> Save, Cancel Thanks Quote Link to comment https://forums.phpfreaks.com/topic/108059-dynamic-page-editing/ Share on other sites More sharing options...
BillyBoB Posted May 30, 2008 Share Posted May 30, 2008 Um I think what you are looking for is javascript. Because you can't edit the looks of a page after it is loaded with php. Some of your question is in php too. Like the logged in info, but that is easy to do. Quote Link to comment https://forums.phpfreaks.com/topic/108059-dynamic-page-editing/#findComment-553885 Share on other sites More sharing options...
soycharliente Posted May 30, 2008 Share Posted May 30, 2008 It's fairly easy. Just do exactly what you said. Check to see if they are logged in. If they are, then have a link. Format the edit link like page.php?action=edit Use the $_GET method to check to see if isset($_GET['action']) and $_GET['action'] == "edit" If it does, don't just grab the text, but paste a textarea with the text inside of it. Give them a save button and cancel button. The cancel button would just take you to page.php (no action=edit so it would just render text) and the save button would do the same but also update the data in the database. Quote Link to comment https://forums.phpfreaks.com/topic/108059-dynamic-page-editing/#findComment-553887 Share on other sites More sharing options...
gizmola Posted May 30, 2008 Share Posted May 30, 2008 Define simple. What wiki's and most CMS do isn't simple, for example a wiki does translation of wiki markup to html. Let's assume you're not going to have any of that, and will allow raw unexpergated html. In short, these systems store the content of the pages inside a database, and then render the output and translate it into html. Allowing editing of that could be as simple as displaying it inside an html form textarea. You simply pull the row that is stored in the db, and output it to the textarea. The only thing remotely tricky is remembering to escape and unescape the content. With mysql you would use mysql_real_escape_string. Quote Link to comment https://forums.phpfreaks.com/topic/108059-dynamic-page-editing/#findComment-553888 Share on other sites More sharing options...
andrewgarn Posted May 30, 2008 Author Share Posted May 30, 2008 So it would require the content to be stored in a database? and i can do the login stuff ,thats easy. No way of changing the html without a database? i thought about reading from a text file, editing in a box then writing it back? Quote Link to comment https://forums.phpfreaks.com/topic/108059-dynamic-page-editing/#findComment-553918 Share on other sites More sharing options...
.josh Posted May 31, 2008 Share Posted May 31, 2008 yes, you can use a text file as an alternative to a database. Quote Link to comment https://forums.phpfreaks.com/topic/108059-dynamic-page-editing/#findComment-553986 Share on other sites More sharing options...
blufish Posted May 31, 2008 Share Posted May 31, 2008 make a page with a form with a textarea (newtext). when submited send it to a php sorta like this one $pagetext = $_POST['newtext']; /* ez */ file_put_contents("pagetext.pag",$pagetext); echo "<h1>Dude! you just changed the page!</h1>"; note: the page with a form should do something like this: $pagecontents = file_get_contents(pagetext.pag); echo "<form action='writethestuff.php' method='post'><textarea rows='10' cols='30'>".$pagecontents."</textarea></form>"; to read the file use a file like this: echo "You can edit anything below this"; $readit = file_get_contents(pagetext.pag); echo $readit; echo "Except for this"; put this code where I wrote /* ez */ to write your own page syntax, like wikipedia. $pagetext = strip_tags($pagetext); /* Strips HTML and PHP tags */ $pagetext = str_replace("[b]","<b>",$pagetext); $pagetext = str_replace("[/b]","</b>",$pagetext); I hope you understood that.. If you're looking to do dynamic editing, like gmail, I think it's AJAX. There are things out there that as you edit html text show you what you're editing in another, their usually called "scratch pads" or something. And they use Javascript. Quote Link to comment https://forums.phpfreaks.com/topic/108059-dynamic-page-editing/#findComment-554031 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.