Jump to content

Dynamic Page Editing


andrewgarn

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.