Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 22
Like Tree1Likes

Thread: Cancel an edit from a logic hook

  1. #11
    luisfdo's Avatar
    luisfdo is offline Member
    Join Date
    Apr 2008
    Posts
    8

    Default Re: Cancel an edit from a logic hook

    hi Superman, i tried your way to get messages on the editview, but i'm getting this error:

    Warning: Invalid argument supplied for foreach() in /home/.hobbes/lotusftp/lotus.calixnet.com/modules/calix_Temas_Gescom/views/view.edit.php on line 6

    here is my view.edit.php
    PHP Code:
    <?php

    require_once('include/MVC/View/views/view.detail.php');

    require_once(
    'include/MVC/View/views/view.edit.php');


    class 
    calix_Temas_GescomViewEdit extends ViewEdit {


      public function 
    display() {

        foreach (
    $_SESSION['calix_Temas_Gescom'] as $field_name => $value) {

          if (isset(
    $this->ev->fieldDefs[$field_name])) {

            
    $this->ev->fieldDefs[$field_name]['value'] = $value;

          }

        }

        
    parent::display();

      }


    }  

    ?>


    Thank you

  2. #12
    ash
    ash is offline Sugar Community Member
    Join Date
    Apr 2008
    Posts
    19

    Default Re: Cancel an edit from a logic hook

    This is great...thanks!

    Quote Originally Posted by Superman View Post
    Prefilling EditView form with data from SESSION or GET is quite intuitive.
    Example for module Case:
    1. $_SESSION should be constructed as
    $_SESSION['Cases']['name'] = 'blabla';
    $_SESSION['Cases']['priority'] = 'chihuahua';
    $_SESSION['Cases']['assigned_user_id'] = 'user_identification_string';

    2. We are loading EditView screen, let's prefill fields.
    There are several ways of where we could place code, I choose /custom/modules/Cases/views/view.edit.php
    PHP Code:
    require_once('include/MVC/View/views/view.detail.php');
    class 
    CasesViewEdit extends ViewEdit {
      public function 
    display() {
        foreach (
    $_SESSION['Cases'] as $field_name => $value) {
          if (isset(
    $this->ev->fieldDefs[$field_name])) {
            
    $this->ev->fieldDefs[$field_name]['value'] = $value;
          }
        }
        
    parent::display();
      }


  3. #13
    luisfdo's Avatar
    luisfdo is offline Member
    Join Date
    Apr 2008
    Posts
    8

    Default Re: Cancel an edit from a logic hook

    I get it. My code is like this:

    PHP Code:
    require_once('include/MVC/View/views/view.edit.php');
    require_once(
    'data/SugarBean.php');


    class 
    myModuleViewEdit extends ViewEdit {



        public function 
    display() {

              
            if(isset(
    $_SESSION ['myModule']) && isset($_SESSION ['erro']) ){

                echo 
    '<p class="error">';
                echo 
    '<b>';
                echo 
    $_SESSION['erro'];
                echo 
    '</b>';
                echo 
    '</p>';
                foreach (
    $_SESSION ['myModule'] as $field_name=>$value) {

                    if (isset(
    $field_name)) {

                        
    $this->ev->focus->$field_name $value;
                    }
                }

                unset (
    $_SESSION ['myModule']);
                unset (
    $_SESSION ['erro']);
                
             

            }
            
    parent::display();
        }



    And I seed two $_SESSION arrays in the logic_hook function. One called 'myModule' and another called 'erro'.

    This way I can print an occasional error, and fill the form.
    Last edited by luisfdo; 2009-01-23 at 05:24 PM.

  4. #14
    Snook is offline Sugar Community Member
    Join Date
    Jan 2007
    Posts
    52

    Default Re: Cancel an edit from a logic hook

    What about using the toArray() and fromArray() functions instead ?

    To Create the session :
    PHP Code:
    $_SESSION['temporaryData'] = $focus->toArray(); 
    And restore the bean:
    PHP Code:
    $focus->fromArray($_SESSION['temporaryData']); 
    - Damien
    :: Keep Open Spirit ::

  5. #15
    SugarDev.net is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    1,401

    Default Re: Cancel an edit from a logic hook

    Nice Damien .
    Developers go here
    Businesses go there (Dutch)

    Modules:
    SugarDev.net Developer Tools | Config | Dutch Language Pack
    "Nothing gets fixed unless there is a bug"

  6. #16
    sivaprabu is offline Member
    Join Date
    Sep 2009
    Posts
    13

    Default Re: Cancel an edit from a logic hook

    Hi all,

    I am using version 5.2.0f CE

    I have done redirect logic_hook from edit view page and I try to fill values in edit view page its not working and also how display error message like "Entered email address already exists" ..
    in edit view page.............


    please help me...


    PHP Code:
    <?php
    if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    require_once(
    'include/MVC/View/views/view.edit.php');
    class 
    CasesViewEdit extends ViewEdit {
      public function 
    display() {
        foreach (
    $_SESSION['vendor_management'] as $field_name => $value) {
          if (isset(
    $this->ev->fieldDefs[$field_name])) {
                
    $this->ev->fieldDefs[$field_name]['value'] = $value;
            
          }
        }
        
    parent::display();
      }
    }  
    ?>

  7. #17
    Join Date
    Apr 2009
    Posts
    16

    Default Re: Cancel an edit from a logic hook

    Hi, I am trying to implement this "block the save" and "redirect to editview" strategy, to try and implement some business rules server-side. I am not having any joy trying to "redirect to editview" when the starting point is a subpanel quickcreate. Is there any way to do this? Thanks in advance.
    Last edited by SugarBeginnerUK; 2009-12-13 at 04:58 AM.

  8. #18
    enrashid is offline Sugar Community Member
    Join Date
    Apr 2008
    Posts
    59

    Default Re: Cancel an edit from a logic hook

    Quote Originally Posted by luisfdo View Post
    I get it. My code is like this:

    PHP Code:
    require_once('include/MVC/View/views/view.edit.php');
    require_once(
    'data/SugarBean.php');


    class 
    myModuleViewEdit extends ViewEdit {



        public function 
    display() {

              
            if(isset(
    $_SESSION ['myModule']) && isset($_SESSION ['erro']) ){

                echo 
    '<p class="error">';
                echo 
    '<b>';
                echo 
    $_SESSION['erro'];
                echo 
    '</b>';
                echo 
    '</p>';
                foreach (
    $_SESSION ['myModule'] as $field_name=>$value) {

                    if (isset(
    $field_name)) {

                        
    $this->ev->focus->$field_name $value;
                    }
                }

                unset (
    $_SESSION ['myModule']);
                unset (
    $_SESSION ['erro']);
                
             

            }
            
    parent::display();
        }



    And I seed two $_SESSION arrays in the logic_hook function. One called 'myModule' and another called 'erro'.

    This way I can print an occasional error, and fill the form.
    This is an ingenious way to cancel a save operation AND to show an appropriate error message. Unfortunately this is flawed for PRO and ENT versions because they both have field-level permissions which you can make a field readonly.

    Let me explain: the problem occurs when you retrieve the values using the above method and populate each of the field variables, you will NOT be able to save these readonly fields when you press the save button (assuming that all validations pass) because view.edit.php respects the role-based permissioning for that user. You may see the value in the readonly field in the EditView, but when you save, the NULL value will actually be stored in the db, not the value that you stored in the SESSION variable. The view.edit.php is not run just like logic hooks, but is run with the permissions of the role(s) the user has. This makes no sense at all since this file is trying to automate a task just like logic hooks and should be run accordingly, but instead it is run as though a user was populating the fields with its permissions.

    Generally, SugarCRM did NOT do a good job to create a proper framework on data validation to show error messages. Something very simple that you would find in off-the-shelf apps, but not in Sugar. Strange.

  9. #19
    Join Date
    Apr 2009
    Posts
    16

    Default Re: Cancel an edit from a logic hook

    This is brilliant and I have been using this across all modules in CE. I noticed today that it doesn't work when you edit from the list view, and then click "Save & Continue" instead of "Save".

    Did I miss some obvious code? Thanks.

  10. #20
    z3r0 is offline Sugar Community Member
    Join Date
    May 2009
    Posts
    189

    Default Re: Cancel an edit from a logic hook

    Quote Originally Posted by Superman View Post
    Prefilling EditView form with data from SESSION or GET is quite intuitive.
    Example for module Case:
    1. $_SESSION should be constructed as
    $_SESSION['Cases']['name'] = 'blabla';
    $_SESSION['Cases']['priority'] = 'chihuahua';
    $_SESSION['Cases']['assigned_user_id'] = 'user_identification_string';

    2. We are loading EditView screen, let's prefill fields.
    There are several ways of where we could place code, I choose /custom/modules/Cases/views/view.edit.php
    PHP Code:
    require_once('include/MVC/View/views/view.detail.php');
    class 
    CasesViewEdit extends ViewEdit {
      public function 
    display() {
        foreach (
    $_SESSION['Cases'] as $field_name => $value) {
          if (isset(
    $this->ev->fieldDefs[$field_name])) {
            
    $this->ev->fieldDefs[$field_name]['value'] = $value;
          }
        }
        
    parent::display();
      }

    Now Sugar 6.4 available. When you change the edit.view.php still? The code is dirty. For there can be problems with other programmers who make the same and install this with her packages. What is the better solution? Where are the offical sugar gurus

Page 2 of 3 FirstFirst 123 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Cancel save in logic hook
    By eggsurplus in forum Developer Help
    Replies: 4
    Last Post: 2012-02-08, 10:37 AM
  2. Logic Hook - Works in custom, not in main
    By spyro187 in forum Developer Help
    Replies: 4
    Last Post: 2008-06-09, 08:19 PM
  3. useful logic hook.. php newbie
    By ispytodd in forum Developer Help
    Replies: 8
    Last Post: 2006-12-28, 02:31 PM
  4. Adding Logic Hook to existing
    By Superman in forum Developer Help
    Replies: 2
    Last Post: 2006-12-18, 10:38 PM
  5. Logic Hook Question
    By swhitlow in forum Developer Help
    Replies: 1
    Last Post: 2006-06-04, 05:49 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
  •