Solved

scriptaculous Ajax.InPlaceEditor server side script assistance

Posted on 2007-11-26
5
904 Views
Last Modified: 2013-12-12
Hello,

I am having a little difficulty understanding how to pass and return information using scriptaculous' Ajax.InPlaceEditor.  According to the website the format is as such:

new Ajax.InPlaceEditor( element, url, [options]);

The part that I am having a problem with is the url on the server-side.  When I modify the text area, the modified info is somehow passed to this url, however it is not clear on how to process this or what variables it's using (ie, POST, GET, etc?)  I am using PHP and it would be great to know if I can modify a cell from a table and pass it (using POST) to a php file which will in turn, update my mysql database (which contains that data) and return the updated value.  So for instance, if I have a table as such:

+--------+--------+-----+
| data1  |  data2  |  ID  |
+--------+--------+-----+

and the user updates the contents of data2, I would like to update the mysql table that contains that information, based on the ID of the row changed.  I am confused as to how to pass that (as a POST) to the url given above and how it can return that info.

Many Thanks!
0
Comment
Question by:con2007
  • 3
5 Comments
 

Author Comment

by:con2007
ID: 20358863
To all experts out there, am I not asking this question correctly?  Does it need re-writing?  I'm not sure if my question is not making sense as I've not received any responses yet...

0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 20358975
Given this:
<p id="editme">Click moi, click me!</p>

If you were to call send it simply as:
new Ajax.InPlaceEditor('editme', 'save.php');

on the server you would get the updated content as:
$_POST['value'], which would evaluate to "Click moi, click me!", but that's the only thing passed to the server (based on my observation), so you don't really know which field this "updated value" is associated to.
Just so we are clear, the "default" field name containing the updated value is "value" and the default method is "POST".

The following will "POST" the content of the "editme" paragraph with some additional parameters:

  new Ajax.InPlaceEditor('editme', 'save.php', { ajaxOptions:{method:'post'}, callback: function(form, value) { return 'thisvar=true&thatvar=Howdy&editMe=' + escape(value) }})

On the server:
$_POST['thisvar'] will evaluate to "true";
$_POST['thatvar'] will evaluate to "Howdy";
$_POST['editMe'] will evaluate to "Click moi, click me!";

The trick is to use a "callback" function which returns a string containing all the parameters that you intend to "POST". When a "callback" function is used, you must append the updated value. By default, the callback function will receive the updated value as the second parameter. Hence, on the example above, I "renamed" the default field from "value" to "editMe", and then assigned the updated value to it before it gets posted.
0
 

Author Comment

by:con2007
ID: 20359207
Many Thanks hielo, that was exactly what I needed!!
0
 
LVL 1

Expert Comment

by:Beckerist
ID: 20937900
This is also valid (php is the example I use, can apply to any:)

You can pass $_GET["var1"] to save.php too...
<?

echo "new Ajax.InPlaceEditor('editme', 'save.php?var1=" . $var1 . "');";

?>

Open in new window

0
 

Author Comment

by:con2007
ID: 20939196
Thanks Beckerist - good to know it can pass strings in the URL as well!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now