Sugarcrm Tutorial : How to use ajax with sugar
Hello people, I always ask my self how to embed ajax within sugar, it is to look at an EditView of a contact and to do some action without refreshing the browser. Well, after a little study, I could do it, so I will share it with you how to add ajax in sugar.
I will explain how to add to an EditView a buttom that when we click on it, it executes a php application and bring its content. The invocation to that php file will be using YUI (yahoo user interface). The idea is, when we press the button, it will call an external php that will execute its code and it will get a param from sugar.
First at all, we have to install an exelent module developed by patrizio gelosi named EnhancedStudio, This module adds a new type of field named ‘Code’ field, that will help us to add php code and a lot of things more.
After install this module, we have to add the code field to the editview of contacts module, to do this we have to:
1- Go to Admin->Studio->Contacts->Fields. We have to add a new ‘Code’ field name ‘yui_test’
2- We have to add the following code:
<script>
function invoke() {
alert(”Button clicked!”);
var callback = {
success: function(o) {
document.getElementById(”div_info”).innerHTML =
o.responseText;
}
}
var connectionObject = YAHOO.util.Connect.asyncRequest (”GET”, “http://localhost/sugarcrm/my_app.php?name=’
. $bean->first_name . ‘”, callback);}
</script>
<input type=”button” id=”boton” name=”button” value=”Execute PHP” onclick=”invoke();”>
<div id=”div_info”>
<b>this will change…</b>
</div>
‘
4- Finally, we must create the file to be invoked. To do this we must create “my_app.php” within sugarcrm root directory. The content is the following:
for ($i=0; $i < 5; $i++) {
echo “Hello world! $i<br>”;
}
echo ‘<br><br><br><br><br><iframe src=”http://es.wikipedia.org/wiki/Iframe”
width=”400″ height=”500″ scrolling=”auto” frameborder=”1″ transparency>
<p>Alternative text for iframe.</p>
</iframe>
‘;
With all of this, I wanted to show the potential and ease at time to add code in sugar
If you have any problem with the code, let me know and I’ll try to help you.
Cheers and sorry for the horrible english! 
Fine the top level SY0-201 CompTIA Security+ certification guide. We are here to server you better than ever. We have designed Cisco ISCW 642-825 and 650-393 LCSE Cisco Lifecycle Services Express exam preparation guide to help you pass these exams easily. Our pdf exam tutorial of 640-460 IIUC Implementing Cisco IOS and 642-373 CXFS and Cisco 642-436 will help you get highest scores.
posted by: http://expertzweb.com

excellent example.
i installed the module. then when i tried to create a field using the studio it did not display the field list , i tried after clearing cache but of no use.
2. so you are trying to create field with name—-code and its label is ‘yui_test’. am i correct. correct me if i’m wrong.
3. in which file do you want me to make these changes
1- Go to Admin->Studio->Contacts->Fields. We have to add a new ‘Code’ field name ‘yui_test’
2- We have to add the following code:
PHP Code:
echo ‘
function invoke() {
alert(”Button clicked!”);
var callback = {
success: function(o) {
document.getElementById(”div_info”).innerHTML =
o.responseText;
}
}
var connectionObject = YAHOO.util.Connect.asyncRequest (”GET”, “http://localhost/sugarcrm/my_app.php?name=’
. $bean->first_name . ‘”, callback);
}
this will change…
‘
;
waiting for reply.
As the title suggests, an introduction to statistics for novices. ,