Results 1 to 5 of 5

Thread: form validation

  1. #1
    splinters is offline Member
    Join Date
    Jan 2007
    Posts
    9

    Default form validation

    does anyone know a way (or maybe know of an available module) that would allow me to make a form element required or not required based on the value of another field -- would be nice to actually have certain fields start out a disabled until the value of a second field triggers the first field to become enabled

    thanks a lot
    splinters

  2. #2
    ruchida's Avatar
    ruchida is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Feb 2005
    Location
    Japan
    Posts
    1,375

    Default Re: form validation

    Hi

    SugarCRM has lots of Javascripts functions to check a form in include/javascript/sugar_3.js. You can register as many fields as you like beforehand, with some conditions, and the check_form() functions validate them later.

    For example, the following HTML script (triggered by Save button) registers certain fields by calling a custom function add_check(). The check_form() then validate them.
    PHP Code:
    <input title="{APP.LBL_SAVE_BUTTON_TITLE}" accessKey="{APP.LBL_SAVE_BUTTON_KEY}" class="button" onclick="this.form.action.value='Save'; return (add_checks(document.EditView) && check_form('EditView'));" type="submit" name="button" value="  {APP.LBL_SAVE_BUTTON_LABEL}  " 
    In add_check(), you can add a policy and register some fields to validate by calling addToValidate() as follows.
    PHP Code:
    function add_checks(f) {
        if (
    f.name.value != "") {
            
    addToValidate('EditView''date_start''date''true''{$mod_strings['LBL_DATE_TIME']}');
            
    addToValidate('EditView''duration_hours''int''true''{$mod_strings['LBL_MAIL_SMTPPORT']}');
        }
        return 
    true;

    In this policy, if a user input something in the 'name' field, two additional fields - 'date_start' and 'duration_hours' - can not be blank.
    Ryuhei Uchida
    Help Forum Moderator
    Calendar 2.0
    http://blogs.itmedia.co.jp/ruchida/

  3. #3
    splinters is offline Member
    Join Date
    Jan 2007
    Posts
    9

    Default Re: form validation

    excellent -- thanks for the reply --- need to talk to my production admin to get that kinda access to the box -- but sounds easy enough to toy with ---

    thanks

  4. #4
    ELFella is offline Junior Member
    Join Date
    Apr 2007
    Posts
    3

    Default Form validation

    Hello,

    I have a similar question, I am looking to add some validation to some of the fields when you create or edit a lead, contact, or account.



    I would like to check the following fields for validation

    Phone number : I would like it to be make it to where it has to be in a certain format i.e 000-000-0000 instead of being able to put anything in

    Zip Code: I would like to make this field in a preset format as well 00000-000

    Names - Is there a way to automatically make the first letter capital?



    Thanks in advance for any help,

    Erin

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

    Default Re: form validation

    Hello Ruchida, is very interesting your answer, I'm intenting it, but I have errors.
    I'm trying to do some works on a function "custom" I call it <imput title...................return Custom(document.EditView...................>

    I havem't idea where to place php function "custom" i've intented in the same editview and in my_custom_module.php without good results. Simply the program doesn't go into the function

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Linking web form to Sugar
    By brandx in forum General Discussion
    Replies: 2
    Last Post: 2007-05-11, 08:39 AM
  2. Inserting new leads via external form
    By rbarrero in forum Developer Help
    Replies: 4
    Last Post: 2006-07-28, 09:49 PM
  3. Inserting new leads via external form
    By rbarrero in forum General Discussion
    Replies: 0
    Last Post: 2006-07-27, 10:37 PM
  4. Looking for web-based lead input form. v. 3.5.1
    By pozole in forum Classifieds
    Replies: 5
    Last Post: 2006-06-05, 07:58 AM
  5. Adding Form Fields to an Email Template
    By miles932 in forum Help
    Replies: 1
    Last Post: 2006-01-06, 08: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
  •