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

Custom new filed

I'm tryng to add a custom field in the osticket, something like Serial No. Company Name and so on...

I've allready done it in osticket 1.6 but after the upgrade in 1.6 i've find some trouble, there's anyone that have allready do it?

First step is for sure:
ALTER TABLE ost_ticket ADD COLUMN `serial` VARCHAR(45) NULL  AFTER `updated` ;


If you need some other fields, just replace 'serial' with a name of the field that you required.

Then we need to change the following file:

/osticket dir/include/class.ticket.php

Where the '....' are the other var of the class

class ticket {
....
....
var $serial; // Mod For a Custom Field by LarsSalazar


After this changes we need to add a function get in getter section.

class ticket {
// Mod function for get serial by LarsSalazar
function getSerial(){
return $this->ht['serial'];
}


Still in the getter section find the function getUpdateInfo() in $info array

class ticket {
$info=array('name' => $this->getName(),
...........
...........
'subject' => $this->getSubject(),
//mod for serial field by LarsSalazar
'serial' => $this->getSerial(),
............


Still in the same file, in function update() in $fields array add this string after $fields['phone']

// Mod for new field by LarsSalazar
$fields['serial'] = array('type'=>'text', 'required'=>0, 'error'=>'Invalid Serial');


in fucntion create() in $fields array add this string after $fields['email']

//Mod for new field by LarsSalazar
$fields['serial'] = array('type'=>'text', 'required'=>0, 'error'=>'Invalid Serial');


Still in function create find the following code

$sql = 'INSERT INTO'
......
.' ,email='.db_input($vars['email'])

and add

// Mod add field by LarsSalazar
.' ,serial='.db_input($vars['serial'])


/osticket dir/include/client/open.inc.php after the following code

<tr>
<th>Telephone:</th>
<td>

<input id=\"phone\" type=\"text\" name=\"phone\" size=\"17\" value=\"<?php echo $info['phone']; ?>\">
<label for=\"ext\" class=\"inline\">Ext.:</label>
<input id=\"ext\" type=\"text\" name=\"phone_ext\" size=\"3\" value=\"<?php echo $info['phone_ext']; ?>\">
<font class=\"error\">&nbsp;<?php echo $errors['phone']; ?>&nbsp;&nbsp;<?php echo $errors['phone_ext']; ?></font>
</td>
</tr>

add

<!-- Mod for new field by LarsSalazar-->
<tr>
<th>Serial:</th>
<td>
<input id=\"serial\" type=\"text\" name=\"serial\" size=\"17\" value=\"<?php echo $info['serial']; ?>\">
<font class=\"error\">*&nbsp;<?php echo $errors['serial']; ?></font>
</td>
</tr>
<!-- Mod for new field by LarsSalazar-->


/osticket dir/include/client/view.inc.php after the following code

<tr>
<th>Phone:</th>
<td><?php echo $ticket->getPhoneNumber(); ?></td>
</tr>

add

<!-- Start Mod custom Field by LarsSalazar -->
<tr>
<th>Serial:</th>
<td><?php echo $ticket->getSerial(); ?></td>
</tr>
<!-- End Mod custom Field by LarsSalazar -->

/osticket dir/include/staff/ticket-view.inc.php

<tr>
<th>Phone:</th>
<td><?php echo $ticket->getPhoneNumber(); ?></td>
</tr>

add

<!-- Start Mod custom Field by LarsSalazar -->
<tr>
<th>Serial:</th>
<td><?php echo $ticket->getSerial(); ?></td>
</tr>
<!-- End Mod custom Field by LarsSalazar -->

Comments

  • Any update on this? I would like to add a Company Name Field to our tickets as well, I would want it available for when the user, or staff create the ticket, and also make it required in order to submit the ticket.

    Any information would be appreciated.
  • Because cross posting about the same thing more then once is bound to get you better results right?
  • ntozier;37711 said:
    Because cross posting about the same thing more then once is bound to get you better results right?
    Actually I did not double post, I actually recommended this in the recommendations section, and then asked the previous poster if he has had any luck.
  • ntozier;37711 said:
    Because cross posting about the same thing more then once is bound to get you better results right?
    If that warning is for me, i apologize... and i'm really sorry. If is the case, please close the post and i'll update the post in wich i'm talking about new custom field.

    @CV_Frank

    at the moment i've got some trouble, i'll try to fix it and post it.

    the steps are not so complicated:

    Alter the table ost_ticket, couse you need to add the custom field(s) in to the database.

    Add get and set in to the class ticket.

    Check it and add the right html/php code in to the files that allow the user and the staff create and update the ticket.

    PHP is not my best, i'm using it something like 2/3 weeks, but i think and hope to end the mod as soon as possible. if you find something about it i appreciate if you want to post the link here.
  • LarsSalazar;37720 said:
    If that warning is for me, i apologize... and i'm really sorry. If is the case, please close the post and i'll update the post in wich i'm talking about new custom field.

    @CV_Frank

    at the moment i've got some trouble, i'll try to fix it and post it.

    the steps are not so complicated:

    Alter the table ost_ticket, couse you need to add the custom field(s) in to the database.

    Add get and set in to the class ticket.

    Check it and add the right html/php code in to the files that allow the user and the staff create and update the ticket.

    PHP is not my best, i'm using it something like 2/3 weeks, but i think and hope to end the mod as soon as possible. if you find something about it i appreciate if you want to post the link here.
    Thank you, But I am even newer to this stuff than you!!! I can discern what you are saying, but I will need help with the last part!
  • Mod completed and in the afternoon i'll post it. Stay tuned
  • Thank you. I will.
  • i've added the code to create new custom field.
  • The code did not work for me. It actually broke my website, I substituted Serial for Company and the whole site is down, I am going to reupload the back up files now. Error I get is HTTP 500
  • ALTER TABLE ost_ticket ADD COLUMN `serial` VARCHAR(45) NULL AFTER `updated`

    Where do I do this at? in SQL Database itself or do I enter this code somewhere in OSTicket?

    I have only MySQL Access, when I click on os_ticket it lists a huge table of stuff. The Table Columns are labeled like this:
    Field | Type | Collation | Attributes | Null | Default |Extra

    I Added This:

    company | varchar(45) |utf8_general_ci |  {blank}   |  Yes |  NULL   |{blank}



    Is this correct?
  • I use the shell to make the alter table and so on..

    u need some tool that allow you to do this stuff like workbench or phpmyadmin or use the terminal if you have linux, the right syntax is:

    ALTER TABLE [column name] [action] [what you need]

    obviously u need to set the database. For example with the shell:

    mysql -uroot -p(type the psw)

    use schema (db name);

    ALTER TABLE ost_ticket ADD COLUMN `serial` VARCHAR(45) NULL AFTER `updated`;
  • I used myPHPAdmin, and they MySQL, and then manually typed it in the box on the right, it added the entry into the table, after I deleted my old entry.

    But now I have a new problem..lol

    I am getting an error whenever any staff tries to login

    "A Valid CSRF Token is Required"

    :confused::eek:
  • CV_Frank;38009 said:
    I used myPHPAdmin, and they MySQL, and then manually typed it in the box on the right, it added the entry into the table, after I deleted my old entry.

    But now I have a new problem..lol

    I am getting an error whenever any staff tries to login

    "A Valid CSRF Token is Required"

    :confused::eek:
    Hi Frank,

    what did you have deleted and where, I don't know your code. The only advice that i can give to you is, take a new and clean version of the osticket, and make the changes. My changes doesn't have impact on the CSRF.

    Another tips, i suggest to you to avoid the phpmyadmin because it have so many violation from scripts and so on. Try to use Workbench or the shell of Linux, to make the changes.
  • LarsSalazar;38028 said:
    Hi Frank,

    what did you have deleted and where, I don't know your code. The only advice that i can give to you is, take a new and clean version of the osticket, and make the changes. My changes doesn't have impact on the CSRF.

    Another tips, i suggest to you to avoid the phpmyadmin because it have so many violation from scripts and so on. Try to use Workbench or the shell of Linux, to make the changes.
    Ok I even tried through the shell Dreamhost provides. I reinstalled OS Ticket from scratch even recreated the MySQL database from scratch.

    I carefully and methodically went through each line of code you gave and copied and pasted it over, including the comments. I can get the new field ('Company') to show up on the Clients side when they choose to create a new ticket, but as soon as they hit Create Ticket and error pops up saying to correct the errors below.

    Inside my Admin Control Panel of OSTicket, I get the same DB Error #1054, so I went back into the MySQL database and the table entry is there!

    Here is my table entry:


    Field | Type | Collation | Attributes | Null | Default |

    company| varchar(255) |utf8_general_ci | blank | Yes| NULL |


    I even tried the default value of varchar(45)

    still nothing...

    I am copying and pasting your code, what am I doing wrong?
    :confused:


    EDIT: Think I got it, I missed one of the getSerial() I did not change to getCompany()
  • CV_Frank;38048 said:


    EDIT: Think I got it, I missed one of the getSerial() I did not change to getCompany()
    U need to check all the code, and need to raplace for example $vars['serial'] in to $vars['Company'] the same for the html tag and function
  • LarsSalazar;38058 said:
    U need to check all the code, and need to raplace for example $vars['serial'] in to $vars['Company'] the same for the html tag and function
    Yup. Got it working.

    Only thing is Company name doesn't show up when staff creates ticket? Does your field serial show up when your staff creates a ticket?

    Any tips?
  • Good, finally you have add your own custom field.

    To show it in to the ticket open by the staff, check the file in:
    /dir osticket/include/staff and add the thml code
  • <tr>
    <tr>
    <td width=\"160\" class=\"required\">
    Company:
    </td>
    <td>
    <input type=\"text\" size=\"50\" name=\"company\" id=\"company\" value=\"<?php echo $info['company']; ?>\">
    &nbsp;<span class=\"error\">*&nbsp;<?php echo $errors['company']; ?></span>
    </td>
    </tr>


    that is what I have added to the ticket-edit.php from \include\staff directory, the field shows up just fine, but when you hit submit I get the error:

    Invalid Company (type not set)

    I am adding this code between line 41-50 on said path
  • Hi Frank,

    ticket-open.php is not the only file that you need to modify. Check all the file i'll try to check mine to help you as soon as possible
  • Extra two mods to do which are not included at the beginning of this post

    The two file mods to include are as follows:
    1. This is already mentioned in post #19 above but the file name is not clear. The file name is actually ticket-edit.inc.php as in...
    \osticket\include\staff\ticket-edit.inc.php
    Find the following code (starting about line Number 31):
    <tr>
    <td width=\"160\" class=\"required\">
    Full Name:
    </td>
    <td>
    <input type=\"text\" size=\"50\" name=\"name\" id=\"name\" value=\"<?php echo $info['name']; ?>\">
    &nbsp;<span class=\"error\">*&nbsp;<?php echo $errors['name']; ?></span>
    </td>
    </tr>

    And then add this code for company - substitute "company" for your own field name (insert at about line 40):

    <!-- Mod for new field-->
    <tr>
    <td width=\"160\" class=\"required\">
    Company:
    </td>
    <td>
    <input type=\"text\" size=\"50\" name=\"company\" id=\"company\" value=\"<?php echo $info['company']; ?>\">
    &nbsp;<span class=\"error\">*&nbsp;<?php echo $errors['company']; ?></font>
    </td>
    </tr>
    <!-- End Mod for new field-->



    2. \osticket\include\staff\ticket-open.inc.php
    Find the following code (starting about line Number 38):

    <tr>
    <td width=\"160\" class=\"required\">
    Full Name:
    </td>
    <td>
    <input type=\"text\" size=\"50\" name=\"name\" id=\"name\" value=\"<?php echo $info['name']; ?>\">
    &nbsp;<span class=\"error\">*&nbsp;<?php echo $errors['name']; ?></span>
    </td>
    </tr>

    And then add this code for company - substitute "company" for your own field name (insert at about line 47):

    <!-- Mod for new field-->
    <tr>
    <td width=\"160\" class=\"required\">
    Company:
    </td>
    <td>
    <input type=\"text\" size=\"50\" name=\"company\" id=\"company\" value=\"<?php echo $info['company']; ?>\">
    &nbsp;<span class=\"error\">*&nbsp;<?php echo $errors['company']; ?></font>
    </td>
    </tr>
    <!-- End Mod for new field-->


    I am having the same problem though when I go back to a ticket and select edit so that I can put in the Company name or replace an existing Company:
    Invalid Company (type not set)
    Can anyone help?
  • /include/class.ticket.php

    This is wrong:
    = array('type'=>'serial',


    change it to:
    = array('type'=>'text',
  • ntozier;38345 said:
    /include/class.ticket.php

    This is wrong:
    = array('type'=>'serial',


    change it to:
    = array('type'=>'text',
    I'll change the code, thx for the advice
  • Cannot edit the data for the new field

    Hi ntozier thank you for pointing out the mistake (this is at about line 1608 in the file ..\osticket\include\class.ticket.php). It now reads as
    $fields['company']    = array('type'=>'text',    'required'=>0, 'error'=>'Invalid Company');

    Substitute 'company' for your own field name as in the rest of this tutorial.
    This eliminates the error:
    Invalid Company (type not set)
    This new field works when you open/create a new ticket and enter the information at that point but it cannot be edited when you go back to the ticket.
    After selecting a ticket in the Staff Panel and then editing the field data you still get no result. The field data remains unchanged.
    Can anyone work out what the reason is?
  • Check $sql = 'UPDATE ..... be sure that you have modified the query to the db, adding the the code for your own custom field
  • Editing and updating the newly adding field in a ticket

    Thank you LarsSalazar. I got this update working and for anyone else out there here is how...
    Adding a new field to your osTicket will include everything mentioned above plus this one last modification (hopefully !!) to the file:
    ..\osticket\include\class.ticket.php
    Find the following code (about line No 1638):
    $sql='UPDATE '.TICKET_TABLE.' SET updated=NOW() '

    and insert somewhere below it the following line of code:
    //Add Company (or whatever your field name is)
    .' ,company='.db_input(Format::striptags($vars['company']))

    Save and FTP this up to your server in the same location
    Now one can go back to an existing ticket and modify/edit the data in your new field like you can with other data.
  • I can say this works, The only thing I missed was on the class.ticket.php file under \include\ directory was a little piece of sql code.

    What would happen to me is I could create the ticket just fine with the company (or whatever you named your custom field) and it would stay, but If I misspelled something and tried to use the edit button on the tickets page, it would not keep the edited text.

    Props to Ntozier for helping out with this one, if you are having the same problem as me, please follow this:


    From Ntozier (He should get all the credits):

    Okay I think that I know what the problem is.
    open /include/class.ticket.php
    locate function update($vars, &$errors) {
    (mine was on line 1591)

    some where in the next 10 or so lines should be a line that looks like this"

    fields['company'] = array('type'=>'string', 'required'=>1, 'error'=>'Company required');

    then below that (mine was on line 1635) is the start of the SQL statement that will update the var in the database. You should have a line that looks somthing like:

    .' ,company='.db_input($vars['company'])

    In bold is what I missing.
Sign In or Register to comment.