Solved

scriptaculous Ajax.InPlaceEditor server side script assistance

Posted on 2007-11-26
5
912 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

733 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