Search: Difference between revisions

From nuBuilderForte
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
Back to [[Documentation]]
== Introduction ==
* '''Search''' is a part of every '''Browse Form'''.
* '''Search''' is a part of every '''Browse Form'''.
* If a <u>special search</u> is to be performed, then call a '''hidden PHP Procedure''' and <tt>return false</tt> and directly execute '''nuForm()'''.
* If a <u>special search</u> is to be performed, then call a '''hidden PHP Procedure''' and <tt>return false</tt> and directly execute '''nuForm()'''.
Line 4: Line 8:
* Encrypting needs to be server-side as if it is in the client side, it will be exposed in the html source in the browser.
* Encrypting needs to be server-side as if it is in the client side, it will be exposed in the html source in the browser.
* Or maybe add an additional button like '''Search SSN''' that calls the PHP Procedure will still enable search for strings that are not encrypted using nubuilder's search button as well.
* Or maybe add an additional button like '''Search SSN''' that calls the PHP Procedure will still enable search for strings that are not encrypted using nubuilder's search button as well.
== Example ==
* Sample Code:
* Sample Code:
<pre>
<pre>
Line 14: Line 20:
</pre>
</pre>
* The search string doesn't exist in '''nuHash()''' so it must be set as a '''Hash Cookie''' (in order to access it in PHP) with <pre>nuSetProperty('nuSearchField', $('#nuSearchField').val());</pre>
* The search string doesn't exist in '''nuHash()''' so it must be set as a '''Hash Cookie''' (in order to access it in PHP) with <pre>nuSetProperty('nuSearchField', $('#nuSearchField').val());</pre>
== Reference Code ==
* Use a separate search button to search for an encrypted string (SSN).
* In this way, searching for unencrypted values will still work as usual.
* In the form's Custom Code:
<pre>
    function nuOnSearchAction() {
     
        window.originalSearchString = undefined;
        return true;
     
    }
    function searchSSN() {
     
          // Store the Search String in a Hash Cookie nuSearchField
          nuSetProperty('nuSearchField', $('#nuSearchField').val());
          // Run the PHP Procedure searchSSN
          nuRunPHPHidden("searchSSN",0);
         
    }
    if(nuFormType() == 'browse'){
          // Add an additional button "Search SSN" next to the other action buttons
          if (window.originalSearchString !== undefined) {
                $('#nuSearchField').val(window.originalSearchString);
          }
         
          nuAddActionButton('nuRunPHPHidden', 'Search SSN', 'searchSSN();');
         
    }
</pre>
* Create a PHP Procedure with
<pre>
    function encryptString($text) {
     
     
      // Use any encryption algorithm and return the encrypted string
      // For demonstration purposes, add 123 to the search string
      $text = $text. '123';
     
      return $text;
    }
    $e = encryptString("#nuSearchField#");
    $js =
    "
      window.originalSearchString = '#nuSearchField#';
      nuForm(nuGetProperty('form_id'),'' , '', '$e', '0');
    ";
    nuJavascriptCallback($js);
</pre>
* Encrypted Search - [https://forums.nubuilder.com/viewtopic.php?f=20&t=10839 Forum Post]
* Encrypted Search - [https://forums.nubuilder.com/viewtopic.php?f=20&t=10839 Forum Post]

Revision as of 11:32, 27 February 2021

Back to Documentation

Introduction

  • Search is a part of every Browse Form.
  • If a special search is to be performed, then call a hidden PHP Procedure and return false and directly execute nuForm().
  • nuOnSearchAction() has been recently introduced in nuBuilder v4.5 that is similar to nuBeforeSave(), parts of the latter can be used in the former.
  • Encrypting needs to be server-side as if it is in the client side, it will be exposed in the html source in the browser.
  • Or maybe add an additional button like Search SSN that calls the PHP Procedure will still enable search for strings that are not encrypted using nubuilder's search button as well.

Example

  • Sample Code:
function nuOnSearchAction() {
    
    nuRunPHPHidden('php_procedure', 0);
    return false;
    
}
  • The search string doesn't exist in nuHash() so it must be set as a Hash Cookie (in order to access it in PHP) with
    nuSetProperty('nuSearchField', $('#nuSearchField').val());

Reference Code

  • Use a separate search button to search for an encrypted string (SSN).
  • In this way, searching for unencrypted values will still work as usual.
  • In the form's Custom Code:
    function nuOnSearchAction() {
       
        window.originalSearchString = undefined;
        return true;
       
    }

    function searchSSN() {
       
           // Store the Search String in a Hash Cookie nuSearchField
           nuSetProperty('nuSearchField', $('#nuSearchField').val());

           // Run the PHP Procedure searchSSN
           nuRunPHPHidden("searchSSN",0);
           
    }

    if(nuFormType() == 'browse'){

           // Add an additional button "Search SSN" next to the other action buttons
           if (window.originalSearchString !== undefined) {
                $('#nuSearchField').val(window.originalSearchString);
           }
           
           nuAddActionButton('nuRunPHPHidden', 'Search SSN', 'searchSSN();');
           
    }
  • Create a PHP Procedure with

    function encryptString($text) {
       
       
       // Use any encryption algorithm and return the encrypted string
       // For demonstration purposes, add 123 to the search string
       $text = $text. '123';
       
       return $text;
    }


    $e = encryptString("#nuSearchField#");

    $js =

    "
      window.originalSearchString = '#nuSearchField#';
      nuForm(nuGetProperty('form_id'),'' , '', '$e', '0');

    ";

    nuJavascriptCallback($js);