Jump to content

[SOLVED] Forms Text Box help


Crew-Portal

Recommended Posts

is it possible to display text with an edit button below, and when the button is clicked the text gets surrounded by a text box and able to be edited and the edit button turns into a save button. And when the save button is clicked it inserts the data into mySQL? And here is the catch... To be able to do so only using one .php page? if someone could show me how to do so I would be really happy and appreative!

Link to comment
Share on other sites

I think you're going to have to do it with JS/ajax, if you wanted something with little/no refreshing.

 

otherwise, you can do something like:

<a href="viewtopic.php?action=edit&id=12345">edit me!</a>

 

<?php 
$action = $_GET['action'];
// clean var

switch($action) {
case 'edit':
//show page with text box and values, and save button
break;
case 'save':
//get vars from $_POST (or $_GET) and save them to the db
break;
}
?>

 

Just a rough outline

Link to comment
Share on other sites

funny... im writing a script library that automates this process...

 

anyway, the basic idea is that your 'edit' button has the id 'actionbutton', and a javascript function that swaps the contents of a block of text for the text area.  the process is quite simple... given the following txt block.

 

<form id="actionform">
<div id="body">  ...content...   </div>
<input type="button" onmouseup="cvert('body')" id="actionbutton" />
</form>

 

for the javascript...

function cvert(e) {
  box = document.getElementById(e);
  ab = document.getElementById("actionbutton");

  box.innerHTML = '<textarea name="body_content">' + box.innerHTML + '</textarea>';
  ab.onmouseup = 'document.getElementById("actionForm").submit()';
}

 

of course, thats just the rough way to do it, ESPECIALLY if your code is post-formatted.  if that is the case, then you will have to go through a ton of AJAX stuff that i am too lazy to post.  this should give  you a basic idea though.

 

(you may want to change "cvert" to something more readable)

 

Link to comment
Share on other sites

Thank you that helps alot but Can you change the Form Function using javascript. And the action of the text box so Upon clicking edit it changes the function to a PHP script that edits information on a mysql database and changing the Edit button to saying something like Save?

 

Sorry I dont know that much about 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.