This topic is locked

Auto-Lookup on field A upon enter data on Field B

10/27/2007 11:47:40 AM
PHPRunner General questions
A
acpan author

Hi,
I am trying to do this:
My Tables:
Order_Table

  1. Telephone Number
  2. Name
  3. Order ID
    Customer_Table
  4. Telephone Number
  5. Name
    I have a form that captures user parameters based on Order_Table:
    ID: Auto_ID
    Tel: __
    Name: __
    When user complete entering telephone, the Name filed will be displayed with the customer name from Customer_Table if succesful match of telephone_number found from Customer_Table.
    If found, it will be displayed, user click save and data updated to Order_Table.
    If not found, user can enter a new name on the Name field and after click save,

    the Order data is saved and the new name and telephone will be also saved to the Customer Table
    Note both name and telephone fields on the form are text field and cannot be a drop down list,

    as it needs to be able to take new values.
    Any idea how to do this effectively would be much appreciated.
    Rgds

    Dex

J
Jane 10/30/2007

Dex,
you can do the following:

  1. setup Telephone Number and Name as dependent dropdown boxes on the "Edit as" settings dialog on the Visual Editor tab and check off Allow to add new values on the fly and Lookup wizard as Edit box with Ajax popup option.
  2. add this code to the After record added event for the Order_Table on the Events tab:
    global $conn;

    $strSelect = "select count(*) from Customer_Table where Telephone_Number='".$values["Telephone_Number"]."'";

    $rs = db_query($strSelect,$conn);

    $data = db_fetch_numarray($rs);

    if ($data[0]>1)

    {

    $strDelete = "delete from Customer_Table where Telephone_Number='".$values["Telephone_Number"]."' and (Name is null or Name='')";

    db_exec($strDelete,$conn);

    }

A
acpan author 10/30/2007

Hi Jane,
Thanks for your response. I have try on the step 1 below and i have not proceed to step 2 as

i am not sure if the delete codes will achieve what i need at first first glance .

Here's what i did on your advice:
On the order form in Visual Editor, I set up as follows:

  1. Telephone_number field: Text Field. (This field captures ANY user input)
  2. name field: Setup in Lookup wizard as follows :
    Lookup Table = Customer_Table

    Link Field = name

    Display Field = name

    Order by = id
    Allow to add new values on the fly = OFF

    Lookup wizard as Edit box with Ajax popup = OFF
    I generated the codes and try on the web. It does not acheieve what i need.
    I need to allow user to do this:
    On the order form tie to Order Table,
    a. Order Taker enters 2 fields: telephone number and name.
    b. When order taker completes entering the telephone_number, the system will use it

    to check against the customer table. If telephone_number is found in Customer_table,

    the order form's name field will be populated with the corresponding name extracted

    from Customer Table.
    c. If telephone_number entered on the order form is not found in Customer Table,

    then Order Taker can enter a new name on the form.
    d. Once the user click save, the event codes After Data Added also store the new customer

    into Customer Table (this part i know how to achieve).
    The tricky part is part b. given the telephone entered by Order Taker, search the customer table

    for the customer name and if found, refresh and display on the order form.
    I think it's similar to another post which you had provided answer via email:

    http://www.asprunner.com/forums/index.php?showtopic=6618
    Thanks for looking into this.

    Dex

J
Jane 10/31/2007

Dex,
there are two ways to do it:

  1. setup Telephone Number and Name as edit boxes with Ajax popup (dependent dropdown boxes) with Add on the fly option.

    In this case you don't need to edit generated files or add code to your pages.
  2. setup these two fields as simpe edit boxes and add custom JavaScript code to this page. You should be familiar with JavaScript and Ajax for that.
    The above solution (http://www.asprunner.com/forums/index.php?showtopic=6618) is for prepopulating field on the add page based on the login info.