Solved

scriptaculous Ajax.InPlaceEditor server side script assistance

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

770 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