Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Call php function from "save" in Editviewdefs

  1. #1
    arffup is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    México DF
    Posts
    54

    Question Call php function from "save" in Editviewdefs

    I have a custom module "incident" with a readonly field, when I save:

    - the read only must receive a valor (like an auto increment)
    - Do some queryes and validate result sets in order to determine if can or not insert in DB the new registry (in case of new incident)
    - validate the default characteristics: required, etc (sugar normal things)

    Obviously i need add some code over "save" button in editviewvardefs.php, I think is like:

    PHP Code:
    'form' => array('buttons'=>array(
                          array(
    'customCode'=>'<input title="{$APP.LBL_SAVE_BUTTON_TITLE}" '.
                                
    'accessKey="{$APP.LBL_SAVE_BUTTON_KEY}" class="button" onclick="this.form.action.value=\'Save\';'.
                                
    'this.form.return_action.value=\'DetailView\'; '.
                                
    'return (IsNewIncident(---------------------) && check_form(\'EditView\'));" '.
                                
    'type="submit" name="button" value="{$APP.LBL_SAVE_BUTTON_LABEL}">'), 
    IsNewIncident is my function.
    Im not sure the arguments, I can use a "form" arguent like document.editview, but so I need a javascript function. I won't to use javascript because I have MySQL functions and I understand javascript can't manage MySQL (java cans but not js) or I can pass only the 3 arguments I really need, like "fields.name.value"

    I want to use a php function. I have one now and I've tested it separately and works correctly. But now the problem is how can I link it whit sugar?

    Since the function determines the value for the redonly field, I need to return it to the "main" code in order to sugar save it with the other fields.

    so: How can I call a php function pushing Save button in Editviewdefs.php?

    thanks very much.

    Windows Server 2003
    Sugar 5.0a
    PHP 5.2.5
    MySQL 5.0
    Apache 2.2.4

  2. #2
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Call php function from "save" in Editviewdefs

    Hi, arffup.

    If you must query the database while saving the record, then you need to use some ajax functionality, invoked by a javascript called onclick the save button, before the invoking of validateform javascript.

    Cheers

    --
    André Lopes
    Lâmpada Global Services
    Rua Bela Cintra, 299 conjunto. 51
    São Paulo, SP 01415-000
    tel1. 55 11 3237-3110
    cel. 55 11 7636-5859
    e-mail: info@lampadacrm.com.br

  3. #3
    arffup is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    México DF
    Posts
    54

    Default Re: Call php function from "save" in Editviewdefs

    Hello, thanks for your answer.

    I don't know really Ajax, so now I have more problems I've checked some tutorials about ajax and I understand this:

    I need my editviewdefs.php calling:
    archive.js calling:
    archive with ajax calling:
    archive.php with the queries ???????????

    This is the way or I'm doing more complex?

    If I understood you well, I need to call my function and then the "check_form" ? then is coorect the next?

    'return (IsNewIncident(---------------------) && check_form(\'EditView\'));" '.


    Thanks very much

    Andrés Reynoso
    (namesake)

  4. #4
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Call php function from "save" in Editviewdefs

    Hi, arffup

    You are studying pretty fine!
    It is the work flow of ajax.

    The parameters send to you javascript function could be the id of field needed to be analyzed and the one needed to be autofilled.

    The javascript could only invoke the php function and fill in the specified field.
    The form validate intrinsic function of Sugar could check if this readonly field is filled in.

    Cheers

    --
    André Lopes
    Lâmpada Global Services
    Rua Bela Cintra, 299 conjunto. 51
    São Paulo, SP 01415-000
    tel1. 55 11 3237-3110
    cel. 55 11 7636-5859
    e-mail: info@lampadacrm.com.br

  5. #5
    arffup is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    México DF
    Posts
    54

    Default Re: Call php function from "save" in Editviewdefs

    hello andopes.

    I don't know why, apparently my javascript (with ajax) doesn´t call the php with the queries. I have proved some examples from tutoriales and always is the same, is how js doesn't call the other file.

    Is it posible invoke a php funtion from 'save' buton? If it is, the precess would be easier


    Thanks

    Andrés Reynoso

  6. #6
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Call php function from "save" in Editviewdefs

    Hi, arffup

    There is no way to do that.
    You must do as ajax itself.

    --
    André Lopes
    Lâmpada Global Services
    Rua Bela Cintra, 299 conjunto. 51
    São Paulo, SP 01415-000
    tel1. 55 11 3237-3110
    cel. 55 11 7636-5859
    e-mail: info@lampadacrm.com.br

  7. #7
    arffup is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    México DF
    Posts
    54

    Default Re: Call php function from "save" in Editviewdefs

    Hello,
    Im using ajax, I've now overcome a lot of problems but I continue thinking is easier with pure php

    Now I have done a process over my read_only field (in php file with queries) but I can't return it, I don't know how trap it with the javascript+ajax code.

    In the other hand, I have some conditions, if I fulfill them I save the entire registry, if not, I don't save it...... But sugar is saving anyway. So i need to return a value o some like that in order to check if can or can't save it

    Thanks

    Andrés

  8. #8
    DragonflyMaster is offline Sugar Community Member
    Join Date
    Dec 2007
    Location
    Rimini, Italy
    Posts
    1,421

    Default Re: Call php function from "save" in Editviewdefs

    Quote Originally Posted by arffup
    Hello,
    Im using ajax, I've now overcome a lot of problems but I continue thinking is easier with pure php

    Now I have done a process over my read_only field (in php file with queries) but I can't return it, I don't know how trap it with the javascript+ajax code.

    In the other hand, I have some conditions, if I fulfill them I save the entire registry, if not, I don't save it...... But sugar is saving anyway. So i need to return a value o some like that in order to check if can or can't save it

    Thanks

    Andrés
    I don't know if it can help you, but it might...
    Look at the "add email address" control inside Accounts' editview:
    this control uses javascript+PHP and also a .tpl file to store an HTML table definition.
    Last edited by DragonflyMaster; 2008-03-30 at 02:08 PM.
    What do you think the cookie monster eats ?

  9. #9
    arffup is offline Sugar Community Member
    Join Date
    Feb 2008
    Location
    México DF
    Posts
    54

    Default Re: Call php function from "save" in Editviewdefs

    Thanks DragonflyMaster

    but I Don't understand the file It has an include for file.js but im not sure where is calling it and i don't found the tpl
    I continue exploring it

  10. #10
    DragonflyMaster is offline Sugar Community Member
    Join Date
    Dec 2007
    Location
    Rimini, Italy
    Posts
    1,421

    Default Re: Call php function from "save" in Editviewdefs

    Quote Originally Posted by arffup
    Thanks DragonflyMaster

    but I Don't understand the file It has an include for file.js but im not sure where is calling it and i don't found the tpl
    I continue exploring it
    Look inside <sugar-root>\include\SugarEmailAddress\
    there you'll see SugarEmailAddress.php and SugarEmailAddress.js and a template subfolder containing .tpl files.
    In forEditView.tpl you can find the layout for the email address form, shown inside account's editview page.
    That form calls functions defined inside SugarEmailAddress.js.
    If you open SugarEmailAddress.js, you'll see those javascript functions using vars, structures and queries defined inside SugarEmailAddress.php, which is required_once in <sugar-root>\modules\Accounts\Account.php.
    It's a kinda complicate mechanism, but after you looked at it, things get clearer.
    What do you think the cookie monster eats ?

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Editview's have stopped appearing
    By atheimer98 in forum Help
    Replies: 12
    Last Post: 2008-12-08, 03:00 PM
  2. PHP Warnings after install add-in Module
    By kgeving in forum Help
    Replies: 1
    Last Post: 2006-08-08, 05:54 PM
  3. Errors after upgrade
    By mturany in forum Help
    Replies: 0
    Last Post: 2006-04-24, 04:40 AM
  4. ERROR in 4.01
    By rateck in forum Help
    Replies: 3
    Last Post: 2006-02-02, 10:00 PM
  5. Replies: 0
    Last Post: 2005-12-18, 08:16 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •