Solved

scriptaculous Ajax.InPlaceEditor server side script assistance

Posted on 2007-11-26
5
905 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

914 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

17 Experts available now in Live!

Get 1:1 Help Now