Crew-Portal Posted August 2, 2007 Share Posted August 2, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/62985-solved-forms-text-box-help/ Share on other sites More sharing options...
Philip Posted August 2, 2007 Share Posted August 2, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/62985-solved-forms-text-box-help/#findComment-313679 Share on other sites More sharing options...
Crew-Portal Posted August 2, 2007 Author Share Posted August 2, 2007 Could you show the code with the Textbox and a variable for the text please? I dont really get what you mean! Quote Link to comment https://forums.phpfreaks.com/topic/62985-solved-forms-text-box-help/#findComment-313680 Share on other sites More sharing options...
ss32 Posted August 2, 2007 Share Posted August 2, 2007 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) Quote Link to comment https://forums.phpfreaks.com/topic/62985-solved-forms-text-box-help/#findComment-313742 Share on other sites More sharing options...
Crew-Portal Posted August 2, 2007 Author Share Posted August 2, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/62985-solved-forms-text-box-help/#findComment-314156 Share on other sites More sharing options...
Crew-Portal Posted August 2, 2007 Author Share Posted August 2, 2007 Nvm I got it figured out! TOPIC SOLVED!!! Quote Link to comment https://forums.phpfreaks.com/topic/62985-solved-forms-text-box-help/#findComment-314231 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.