Results 1 to 10 of 10

Thread: Pre-Populating and Validating Custom Field

  1. #1
    acesfull9 is offline Member
    Join Date
    Jul 2008
    Posts
    6

    Default Pre-Populating and Validating Custom Field

    I added a custom field in the studio and now I need it to be prepopulated on edit/create. Can this be done in a upgrade-safe way?

    Also, I will need to validate the field to make suer it is unique across all the other records. I see that this can be done with a logic_hook, but what do I do if it is not unique? How can I return the user to the edit-view and display an error back to the screen? Or does this have to be an AJAX validation? IF so, can this be done in an upgrade-safe manner?

    Thanks in advance!

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

    Default Re: Pre-Populating and Validating Custom Field

    Quote Originally Posted by acesfull9
    I added a custom field in the studio and now I need it to be prepopulated on edit/create. Can this be done in a upgrade-safe way?

    Also, I will need to validate the field to make suer it is unique across all the other records. I see that this can be done with a logic_hook, but what do I do if it is not unique? How can I return the user to the edit-view and display an error back to the screen?
    I think this can be done using a before_save hook.
    What do you think the cookie monster eats ?

  3. #3
    acesfull9 is offline Member
    Join Date
    Jul 2008
    Posts
    6

    Default Re: Pre-Populating and Validating Custom Field

    Ok so I got it to recognize whether the field is unique on the before_save. Is there a standard way of sending an error back to the screen retaining the user-entered/modified fields?

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

    Default Re: Pre-Populating and Validating Custom Field

    Quote Originally Posted by acesfull9
    Ok so I got it to recognize whether the field is unique on the before_save. Is there a standard way of sending an error back to the screen retaining the user-entered/modified fields?
    How about using a javascript alert() passing to it the field which is wrong?
    What do you think the cookie monster eats ?

  5. #5
    acesfull9 is offline Member
    Join Date
    Jul 2008
    Posts
    6

    Default Re: Pre-Populating and Validating Custom Field

    Quote Originally Posted by DragonflyMaster
    How about using a javascript alert() passing to it the field which is wrong?
    I am talking about in the hook on the server side when the form has already been submitted

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

    Default Re: Pre-Populating and Validating Custom Field

    Hum, as far as I know, before_save is a hook that runs just before saving the edits. I'm talking about the opportunity to run an alert from it.
    What do you think the cookie monster eats ?

  7. #7
    acesfull9 is offline Member
    Join Date
    Jul 2008
    Posts
    6

    Default Re: Pre-Populating and Validating Custom Field

    Quote Originally Posted by DragonflyMaster
    Hum, as far as I know, before_save is a hook that runs just before saving the edits. I'm talking about the opportunity to run an alert from it.
    Ok now I think I am confused. I have the hook set up and I can recognize if there is an error. Could you give an example of a function that runs an alert that you are speaking of? I am familiar with javascript I am just confused about how I would go about doing what you speak of.

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

    Default Re: Pre-Populating and Validating Custom Field

    Quote Originally Posted by acesfull9
    Ok now I think I am confused. I have the hook set up and I can recognize if there is an error. Could you give an example of a function that runs an alert that you are speaking of? I am familiar with javascript I am just confused about how I would go about doing what you speak of.
    Could you post the file with the logic hook?
    What do you think the cookie monster eats ?

  9. #9
    acesfull9 is offline Member
    Join Date
    Jul 2008
    Posts
    6

    Question Re: Pre-Populating and Validating Custom Field

    PHP Code:

        
    function account_before_save(&$bean$event$arguments){
                   
    $cid mysql_connect($host,$usr,$pwd);
                   
    $SQL " SELECT * FROM accounts_cstm where  id_c = '" str_replace("'""''"$bean->account_number_c) . "'";
                   
    $retid mysql_db_query($db$SQL$cid);
                   if (
    $row mysql_fetch_array($retid)) {
                         if(
    $bean->account_number_c != $row["id_cl"]){
                                 
    //there is another account with the same 
                                 
    echo "error";
                                 exit;
                          }
                    }
             } 
    How do I get an error message to display back to the screen with the submitted fields still intact? Is there an easy way? Thanks in advance!

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

    Default Re: Pre-Populating and Validating Custom Field

    Quote Originally Posted by acesfull9
    PHP Code:
     
         
    function account_before_save(&$bean$event$arguments){
                    
    $cid mysql_connect($host,$usr,$pwd);
                    
    $SQL " SELECT * FROM accounts_cstm where  id_c = '" str_replace("'""''"$bean->account_number_c) . "'";
                    
    $retid mysql_db_query($db$SQL$cid);
                    if (
    $row mysql_fetch_array($retid)) {
                          if(
    $bean->account_number_c != $row["id_cl"]){
                                  
    //there is another account with the same 
                                  
    echo "error";
                                  exit;
                           }
                     }
              } 
    How do I get an error message to display back to the screen with the submitted fields still intact? Is there an easy way? Thanks in advance!
    Now I understand what you meant.
    I don't know of any way to call a javascript function from this file.
    What I know is you can add/call javascript code from editviewdefs.php.
    In this manner you can set up an AJAX (js+php) thing...
    What do you think the cookie monster eats ?

Thread Information

Users Browsing this Thread

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

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
  •