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

Ticket Subject automatically from Selected Help Topic

Hi,

I have created a help topic that uses 2 forms (Contact Details and a custom form). In frontend - Create New ticket page, when user selects a topic from drop down, The subject field appears with some other fields.
What I need to do is: When user selects Help topic, subject field will be automatically filled with Topic title.
In dynamic-form.tmpl.php inside foreach, i have used the following :
if (($field->get('name')) == 'subject') {                  }
but i dont know what to put in {}

regards
George






osTicket Version v1.10.1
Web Server Software Apache/2.4.25 (Debian)
MySQL Version 10.1.26
PHP Version 7.0.19-1

Comments

  • Subject is a text field currently.  It's populated with the email's subject, or manually if ticket is created via ui.  The behavior that you are describing is not a feature in osTicket.
  • Hi,
    Im only interested for the manual created via ui. Im planning to add a lot of help topics for user to choose in web form, so subject field will not be necessary.

    Solution :
    Field "subject" is auto filled with help Topic and becomes hidden

    in class.forms.php
    function getFormName() {
            if (is_numeric($this->get('id')))
                        { switch ($this->get('name')) {
                                    case "subject":                                      
                                                return 'formafield' . $this->get('name') ?: $this->get('id');
                                                break;
                                        default:       
                                            return substr(md5(
                                                    session_id() . '-field-id-'.$this->get('id')), -16);
                                        }
                    }
                                        else
                                        {
                                            return $this->get('name') ?: $this->get('id');
                                        }
        }


    in dynamic-form.tmpl.php i added a
    switch ($field->get('name')) {
    case "subject":
                    $field->render(array('client'=>true));
                    ?>
                        <script>
                            var dropo = document.getElementById("topicId");
                            var selectedOp = dropo.options[dropo.selectedIndex].text;
                            var pedio = document.getElementById("_formafieldsubject");
                            pedio.value = dropo.options[dropo.selectedIndex].text;
                            pedio.setAttribute("type", "hidden");
                    </script>
                  
                    <?php
                   
                    break;
                   
    default: 
      if (!$field->isBlockLevel()) { ?>
                            <label  for="<?php echo $field->getFormName(); ?>"><strong><span class="<?php
                                if ($field->isRequiredForUsers()) echo 'required'; ?>">
      ...................
      ...................  }

  • Did this work for you?  

    At what line number did you insert this code in dynamic-form.tmpl.php and also class.forms.php?
  • Yes it works fine.
    In class.forms.php the function getFormName already exists, i just change the code a little bit.
    As for dynamic-form.tmpl.php, the 3 last lines in my code are already in the file, just search for  if (!$field->isBlockLevel()) { ?> and you will find where you have to change code.

    George
  • edited November 10
    Btw, if you want to test it or leave the subject field visible because you want user to change the text, just comment the pedio.setAttribute("type", "hidden"); inside <script> in my code in dynamic-form.tmpl.php
Sign In or Register to comment.