Results 1 to 8 of 8

Thread: Problem with Javascript on Save Button custom code

  1. #1
    swhitlow's Avatar
    swhitlow is offline Sugar Community Member
    Join Date
    Jun 2005
    Location
    Indianapolis, IN.
    Posts
    204

    Red face Problem with Javascript on Save Button custom code

    Hi, I have some custom javascript that I am calling before the Save button submits the form to be saved.

    However, for some strange reason, it only directs me to a page that says this:
    Fatal error: Cannot redeclare class PHPMailer in ../include/phpmailer/class.phpmailer.php on line 21

    And it never saves the information. What is strange is that I know I have been able to do this before. I just can't find the code that I used before and it's driving me nuts!

    Anyone know what I might be missing here?

    Here is the button (in editviewdefs.php file):
    PHP Code:
    'form' => array(
                   
                   
    'buttons' => array(
                                array(
    'customCode'=>'<input id="samples_transfer_save" type="submit" value="Save Transfer" name="button" onclick="this.form.action.value=\'Save\'; return (check_save() && check_form(\'EditView\'));"  class="button" accesskey="S" title="Save [Alt+S]"/>&nbsp;'),
                                
    'CANCEL',
               ),), 
    Notice how in the onclick event I have it calling my own function called check_save() before the check_form() event gets passed. This check_save function works perfectly with no problems. It checks to make sure that the assigned user is not the currently logged in user when saving on a certain module. No problems there.

    Here is the javascript code for check_save():
    Code:
    function check_save() {
       		if(document.getElementById('assigned_user_id').value == '{{$current_id}}') {
       			document.getElementById('warning').innerHTML = 'Error: Explanation of error';
       			$j("#warning").fadeIn("slow");
       			setTimeout('$j("#warning").fadeOut("slow");',20000);
       			return false;
       		}else {
       			return true;
       		}
       	}
    Again, this code works fine. If you are currently logged in as Admin, and try and assign this particualr record to admin, it will display the warning above (obviously, I am using a little jquery to help out).

    However, then I change the assigned user to a different user (which will bypass the if/else statement in the javascript to just return true) and then it brings me to a page that just says the error message about Cannot redeclare class PHPMailer.

    Can anyone help me out with this? I know it's going to be something easy and that I have just been staying up too late programming!

    Thanks!
    Scott Whitlow
    Lead Software Engineer/SugarCRM Developer
    swhitlow at gmail.com
    Indianapolis, IN. USA

  2. #2
    swhitlow's Avatar
    swhitlow is offline Sugar Community Member
    Join Date
    Jun 2005
    Location
    Indianapolis, IN.
    Posts
    204

    Default Re: Problem with Javascript on Save Button custom code

    Nevermind. Got it working. It was a Workflow issue. If anyone ever has any trouble with this error message just post here and I will let you know what I had to do. But, basically, it was an issue with the email settings for a certain user that was being called during a business logic hook.

    Javascript code/save button is working great now!
    Scott Whitlow
    Lead Software Engineer/SugarCRM Developer
    swhitlow at gmail.com
    Indianapolis, IN. USA

  3. #3
    rcastro is offline Senior Member
    Join Date
    Dec 2009
    Posts
    41

    Default Re: Problem with Javascript on Save Button custom code

    Hi, I'm trying to customize the save button. I want to validate a field, if the field doesn't have a valid value I want to show a javascript alert().

    The problem is that I don't know where to put the code 'form' => array( 'button' ...in my editviewdefs.php and I don't know where to put the javascript file and how I include and call the function of the javascript file.

    I would appreciate if you could help me with an example .

    Thanks in advance for your help!

  4. #4
    lijith's Avatar
    lijith is offline Sugar Community Member
    Join Date
    Jun 2009
    Location
    India
    Posts
    67

    Default Re: Problem with Javascript on Save Button custom code

    Check the link below:

    Here
    Lijith M Gopinath
    email : phpbugs@live.com
    website : PHP-Bugs

  5. #5
    infosugarcrm is offline Member
    Join Date
    Apr 2010
    Posts
    7

    Default Re: Problem with Javascript on Save Button custom code

    Dear Experts,

    i had a doubt past 2 months no guide please help me,i created a form ,fields are name,age,through developer studio
    but i want age validation,before save condition is "if age is greater than 50 years display age is higher,if age is less than 50 years display age is lower,(just popup before save)
    i tried i did not get ,
    please provide me code ,
    how to write code?
    where should i place this code?

    and also i want to know how to use logic hooks ? where should i place the location?
    and also i need path of placing logic hooks?
    please let me know

    wating for replay
    S.M.Prasanth

  6. #6
    infosugarcrm is offline Member
    Join Date
    Apr 2010
    Posts
    7

    Post Doubt please :how to validate condition before save the form

    Dear Experts,

    i had a doubt past 2 months no guide please help me,i created a form ,fields are name,age,through developer studio
    but i want age validation,before save condition is "if age is greater than 50 years display age is higher,if age is less than 50 years display age is lower,(just popup before save)
    i tried i did not get ,
    please provide me code ,
    how to write code?
    where should i place this code?

    and also i want to know how to use logic hooks ? where should i place the location?
    and also i need path of placing logic hooks?
    please let me know

    wating for replay
    S.M.Prasanth

  7. #7
    rishavraj's Avatar
    rishavraj is offline Sugar Community Member
    Join Date
    Sep 2010
    Posts
    135

    Default Re: Problem with Javascript on Save Button custom code

    From where can i get this value '{{$current_id}}'

    I am getting this value >pLease help me out

  8. #8
    anatal52 is offline Member
    Join Date
    Apr 2010
    Posts
    5

    Default Re: Problem with Javascript on Save Button custom code

    Hi,we figured it out

    in file: /include/MVC/View/SugarView.php

    In function displayJavascript()

    declare global $current_user;

    and echo var logged_in_user_id = "'.$current_user->id.'";

    Then you'll be able to access logged_in_user_id from any page

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Data won't save in Custom Fields
    By akhorn68 in forum Help
    Replies: 2
    Last Post: 2008-04-30, 05:45 PM
  2. Custom fields don't save any data
    By eringuet in forum Help
    Replies: 21
    Last Post: 2008-04-17, 07:38 AM
  3. Custom Field Problem (bug?)
    By zmao in forum Help
    Replies: 5
    Last Post: 2007-11-13, 05:57 PM
  4. Custom drop-down list problem: using $
    By mgriffin in forum Help
    Replies: 0
    Last Post: 2007-03-30, 06:54 PM

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
  •