Kush Kumar Rai
Kush Kumar Rai

Reputation: 1

How to add a dropdown box for state name in vtiger crm

I have a form and I have to add state name field with a drop down so the user can select name of the state they want from that select box.

How can I do this?

Upvotes: 0

Views: 2229

Answers (4)

Salim
Salim

Reputation: 196

You can use vtlib library for that.

This how we create a state name dropdown Box in Accounts module using vtlib

<?php
$Vtiger_Utils_Log = true;
include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/Module.php');
$module = Vtiger_Module::getInstance('Accounts');
$infoBlock = Vtiger_Block::getInstance('LBL_ACCOUNT_INFORMATION', $module);
$stateField = Vtiger_Field::getInstance('state', $module);
if (!$stateField) {
    $stateField = new Vtiger_Field();
    $stateField->name = 'state';
    $stateField->label = 'State';
    $stateField->columntype = 'VARCHAR(100)';
    $stateField->uitype = 16;
    $stateField->typeofdata = 'V~O';
    $infoBlock->addField($stateField);
    $stateField->setPicklistValues(array('Kerala', 'Karnataka', 'Maharashtra', 'Manipur'));

}

Add the rest of state list in that array.

Hope this helps.

Upvotes: 1

bigN
bigN

Reputation: 21

Assuming you have a databse like mysql.

  • create a table state (state_id, state_name, state_abbr)
  • fetch the states from the state table (write a function to fetch states)
  • iterate in your option of the select box using php script example:

            <select name="state">
              <?php 
                 *// At this point you should have a recordset $rsstate which fetches all the records from the state table*
                while($rowState = mysql_fetch_array($rsState)){?>
                <option value=<?php echo $rowState["state_abbr"]?>><?php echo $rowState["state_name"]; ?></option>
              <?php }?>
             </select>
    

Upvotes: 0

bigN
bigN

Reputation: 21

Assuming you have a databse like mysql.

  • create a table state (state_id, state_name, state_abbr)
  • fetch the states from the state table (write a function to fetch states)
  • iterate in your option of the select box using php script, for example:

    <select name="state">
    <?php
    // At this point you should have a recordset $rsstate which fetches all the records from the state table
    while($rowState = mysql_fetch_array($rsState)) { ?>
        <option value=<?php echo $rowState["state_abbr"] ?>><?php echo $rowState["state_name"]; ?></option>
    <?php } ?>
    </select>
    

Upvotes: 1

manish nautiyal
manish nautiyal

Reputation: 2584

Just go to admin panel and add a picklist. Its very simple.

Upvotes: 0

Related Questions