Answers.Body: <p>I'm assuming you're on Joomla otherwise I'd say try civicrm webform. One option is define custom fields for cases and then use them during hook_civicrm_postProcess. Another is to add some javascript/jquery to the form via hook_civicrm_buildForm or .extra.tpl to pop up a dialog box to get the input, but that seems awkward - your original idea of having another form that comes before seems better.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-02T16:24:27.043Z
Answers.LastActivityDate: 2019-03-02T16:24:27.043Z
Answers.UserDisplayName: Demerit
Answers.Body: <p>API functions can be called in different contexts (eg via API Explorer, command line, in extension code etc) so prompting for user input is not practical but they can require specific parameters.  You could write your API function to require parameters and then figure out how you're going to get the parameters from the user.</p>
  
  <p>That said, I'm not sure an API function is really what you need here.  <code>hook_civicrm_buildForm</code> to add extra bits to the new case form, and <code>hook_civicrm_postProcess</code> for processing the form when it is submitted may be enough.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-05T11:11:05.910Z
Answers.Text: Thanks. Yes, I was hoping to write an API function so I could call the same function from different places, such as a CiviCRM menu and an external script. But it's looking like the form hooks may be the way to go.
Answers.UserDisplayName: Jern
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-05T09:44:19.283Z
Answers.LastActivityDate: 2019-03-05T09:44:19.283Z
Answers.UserDisplayName: Aidan
Body: <p>This may be a stupid question - sorry if so. I am writing an API function to create a new case, and I want it to pre-fill the New Case form with field contents based the case source contact and two or three parameters obtained from the user. Of course I could create a new form in order to collect the user input before displaying the New Case form, but I wondered if there is a way that the API function can interrogate the user in real time to obtain the input parameters? Thanks.</p>
  
Tags: <api><civicase><forms><user-interface>
Title: How to obtain user input from an API call
ThreadText: # How to obtain user input from an API call
  
  (Asked by: username_0 on 2019-03-02)
  
  This may be a stupid question - sorry if so. I am writing an API function to create a new case, and I want it to pre-fill the New Case form with field contents based the case source contact and two or three parameters obtained from the user. Of course I could create a new form in order to collect the user input before displaying the New Case form, but I wondered if there is a way that the API function can interrogate the user in real time to obtain the input parameters? Thanks.
  
  **Tags:** api, civicase, forms, user-interface
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-03-02. Score: 1 | Accepted answer
  
  I'm assuming you're on Joomla otherwise I'd say try civicrm webform. One option is define custom fields for cases and then use them during hook\_civicrm\_postProcess. Another is to add some javascript/jquery to the form via hook\_civicrm\_buildForm or .extra.tpl to pop up a dialog box to get the input, but that seems awkward - your original idea of having another form that comes before seems better.
  
  
  ---
  
  ### Answer by username_2 on 2019-03-05. Score: 0
  
  API functions can be called in different contexts (eg via API Explorer, command line, in extension code etc) so prompting for user input is not practical but they can require specific parameters. You could write your API function to require parameters and then figure out how you're going to get the parameters from the user.
  
  That said, I'm not sure an API function is really what you need here. `hook_civicrm_buildForm` to add extra bits to the new case form, and `hook_civicrm_postProcess` for processing the form when it is submitted may be enough.
  
  > **Comments:**
  > **username_0**: Thanks. Yes, I was hoping to write an API function so I could call the same function from different places, such as a CiviCRM menu and an external script. But it's looking like the form hooks may be the way to go.  
  
  ---
  
  