[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

scriptaculous Ajax.InPlaceEditor server side script assistance

Posted on 2007-11-26
5
Medium Priority
?
929 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …
Suggested Courses

650 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