Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

Ad custom fields to new ticket in v1.7.7

Hello,
I just did the udpate to v1.7.7 and I had custom fields in my previous version that broke in this version. The old way defined var = and the new way uses getters and setters. I fgured out how to call the getter, but I cant figure out how to add the input to the DB. I show the fields on my new ticket form using:

[code]
 <input type="text" name="bizaddress" size="35" value="<?=$info['bizaddress']?>">
 <input type="text" name="bizhours" size="35" value="<?=$info['bizhours']?>">
[/code]

and I tried editing class.ticket.php with:

[code]
 $fields=array();
        $fields['name']     = array('type'=>'string',   'required'=>1, 'error'=>'Name required');
        $fields['email']    = array('type'=>'email',    'required'=>1, 'error'=>'Valid email required');
        $fields['subject']  = array('type'=>'string',   'required'=>1, 'error'=>'Subject required');
        $fields['topicId']  = array('type'=>'int',      'required'=>1, 'error'=>'Help topic required');
        $fields['priorityId'] = array('type'=>'int',    'required'=>1, 'error'=>'Priority required');
        $fields['slaId']    = array('type'=>'int',      'required'=>0, 'error'=>'Select SLA');
        $fields['phone']    = array('type'=>'phone',    'required'=>0, 'error'=>'Valid phone # required');
        $fields['duedate']  = array('type'=>'date',     'required'=>0, 'error'=>'Invalid date - must be MM/DD/YY');

/* custom field */
$fields['bizaddress']  = array('type'=>'string',   'required'=>0, 'error'=>'Address required');
[/code]

and 

[code]
$sql='UPDATE '.TICKET_TABLE.' SET updated=NOW() '
            .' ,email='.db_input($vars['email'])
            .' ,name='.db_input(Format::striptags($vars['name']))
            .' ,subject='.db_input(Format::striptags($vars['subject']))
.' ,bizaddress='.db_input(Format::striptags($vars['bizaddress']))
            .' ,phone="'.db_input($vars['phone'],false).'"'
            .' ,phone_ext='.db_input($vars['phone_ext']?$vars['phone_ext']:NULL)
[/code]


above in the getters I have 

[code]

/* added custom fields */
function getBizaddress() {
        return $this->ht['bizaddress'];
    }

function getBizhours() {
        return $this->ht['bizhours'];
    }

function getBizname() {
        return $this->ht['bizname'];
    }
[/code]

I dont get any errors, butthe custom fields dont get added to the db.  Can anyone advise what I need to change?

Thanks!

Comments

  • edited April 2014
    edit class.ticket.php
    update the function create()
    circa line 2341 - 2348.
    add your variables there like you did in the function update().
  • Thank you for the quick reply, but I do not have that section.

    Whole page code attached

    class_ticket_php.txt
    77K
  • I figured it out. Here is what I added, lmk if it looks wonky (seems to work fine)


            //We are ready son...hold on to the rails.
            $extId=Ticket::genExtRandID();
            $sql='INSERT INTO '.TICKET_TABLE.' SET created=NOW() '
                .' ,lastmessage= NOW()'
                .' ,ticketID='.db_input($extId)
                .' ,dept_id='.db_input($deptId)
                .' ,topic_id='.db_input($topicId)
                .' ,priority_id='.db_input($priorityId)
                .' ,email='.db_input($vars['email'])
                .' ,name='.db_input(Format::striptags($vars['name']))
                .' ,subject='.db_input(Format::striptags($vars['subject']))
    .' ,bizhours='.db_input(Format::striptags($vars['bizhours']))  /* added */
    .' ,bizname='.db_input(Format::striptags($vars['bizname']))  /* added */
    .' ,bizaddress='.db_input(Format::striptags($vars['bizaddress']))  /* added */


    <scroll>

        function getUpdateInfo() {
            global $cfg;

            $info=array('name'  =>  $this->getName(),
                        'email' =>  $this->getEmail(),
                        'phone' =>  $this->getPhone(),
    'bizhours' =>  $this->getBizhours(), /* added */
    'bizname' =>  $this->getBizname(), /* added*/
    'bizaddress' =>  $this->getBizaddress(), /* added */

    <scroll>


        function update($vars, &$errors) {

            global $cfg, $thisstaff;

            if(!$cfg || !$thisstaff || !$thisstaff->canEditTickets())
                return false;

            $fields=array();
            $fields['name']     = array('type'=>'string',   'required'=>1, 'error'=>'Name required');
            $fields['email']    = array('type'=>'email',    'required'=>1, 'error'=>'Valid email required');
            $fields['subject']  = array('type'=>'string',   'required'=>1, 'error'=>'Subject required');
    $fields['bizhours']  = array('type'=>'string',   'required'=>0, 'error'=>'Enter business hours'); /* added  */
    $fields['bizname']  = array('type'=>'string',   'required'=>0, 'error'=>'Enter business name'); /* added */
    $fields['bizaddress']  = array('type'=>'string',   'required'=>0, 'error'=>'Enter business address'); /* added */



    <scroll>

            $sql='UPDATE '.TICKET_TABLE.' SET updated=NOW() '
                .' ,email='.db_input($vars['email'])
                .' ,name='.db_input(Format::striptags($vars['name']))
                .' ,subject='.db_input(Format::striptags($vars['subject']))
    .' ,bizhours='.db_input(Format::striptags($vars['bizhours'])) /* added */
    .' ,bizname='.db_input(Format::striptags($vars['bizname'])) /* added  */
    .' ,bizaddress='.db_input(Format::striptags($vars['bizaddress'])) /* added */

    <scroll>

     //We are ready son...hold on to the rails.
            $extId=Ticket::genExtRandID();
            $sql='INSERT INTO '.TICKET_TABLE.' SET created=NOW() '
                .' ,lastmessage= NOW()'
                .' ,ticketID='.db_input($extId)
                .' ,dept_id='.db_input($deptId)
                .' ,topic_id='.db_input($topicId)
                .' ,priority_id='.db_input($priorityId)
                .' ,email='.db_input($vars['email'])
                .' ,name='.db_input(Format::striptags($vars['name']))
                .' ,subject='.db_input(Format::striptags($vars['subject']))
    .' ,bizhours='.db_input(Format::striptags($vars['bizhours']))  /* added */
    .' ,bizname='.db_input(Format::striptags($vars['bizname']))  /* added */
    .' ,bizaddress='.db_input(Format::striptags($vars['bizaddress']))  /* added */




  • I see you found the function create() I mentioned.  Looks good.
Sign In or Register to comment.