Answers.Body: <p>Paul B,</p>
  
  <p>Its not necessary to have 2 separate tpl for View and edit, the logic can be added in one tpl or php file. But for convenience Civi tries to keep it separate.</p>
  
  <p>A good example for view and add form will be New/Update/ View Membership forms.</p>
  
  <ol>
  <li><strong>The action for CRUD is registered here</strong>
  <a href="https://github.com/civicrm/civicrm-core/blob/master/CRM/Member/xml/Menu/Member.xml#L13" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/master/CRM/Member/xml/Menu/Member.xml#L13</a></li>
  </ol>
  
  <p><a href="https://github.com/civicrm/civicrm-core/blob/master/CRM/Member/xml/Menu/Member.xml#L48" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/master/CRM/Member/xml/Menu/Member.xml#L48</a></p>
  
  <ol start="2">
  <li><p>When above one of the 2 url is hit CiviCRM will execute run() function from <a href="https://github.com/civicrm/civicrm-core/blob/master/CRM/Member/Page/Tab.php#L334" rel="nofollow noreferrer">here</a>. Where you decided which file to invoke for example to create view form process view(), Add/Edit process edit(), listing process browse()</p></li>
  <li><p>Each php file should have tpl associated with it. </p></li>
  </ol>
  
  <p>You can copy paste same file and structure and just change the class name. It should work for you.</p>
  
  <p>HTH</p>
  
  <p>Pradeep </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-04-20T16:53:08.197Z
Answers.LastActivityDate: 2019-04-20T16:53:08.197Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I'm building my first extension, and have created the sample quickform using civix generate:form. So far, so good, the form shows and works within a modal popup.</p>
  
  <p>I've noticed with Core forms (like Contribution edit/view), I can send in an "action" query param, and based on the value of that, the form will either just display a view of the data for that ID, or will show the actual form to edit the data and save it.</p>
  
  <p>I was wondering how I could do that in my custom extension. Do I need to create two sets of php/tpl files, one for editing and one for viewing? Or is there some method or something that will convert the form template to just a view of the fields for me?</p>
  
  <p>If there is a simple example of this type of form (maybe an example extension I could look at), I would appreciate a pointer to it.</p>
  
Tags: <extension><civix><quickform>
Title: Creating a custom Form: Action (view vs update)
ThreadText: # Creating a custom Form: Action (view vs update)
  
  (Asked by: username_0 on 2019-04-20)
  
  I'm building my first extension, and have created the sample quickform using civix generate:form. So far, so good, the form shows and works within a modal popup.
  
  I've noticed with Core forms (like Contribution edit/view), I can send in an "action" query param, and based on the value of that, the form will either just display a view of the data for that ID, or will show the actual form to edit the data and save it.
  
  I was wondering how I could do that in my custom extension. Do I need to create two sets of php/tpl files, one for editing and one for viewing? Or is there some method or something that will convert the form template to just a view of the fields for me?
  
  If there is a simple example of this type of form (maybe an example extension I could look at), I would appreciate a pointer to it.
  
  **Tags:** extension, civix, quickform
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-04-20. Score: 2
  
  username_0,
  
  Its not necessary to have 2 separate tpl for View and edit, the logic can be added in one tpl or php file. But for convenience Civi tries to keep it separate.
  
  A good example for view and add form will be New/Update/ View Membership forms.
  
  1. **The action for CRUD is registered here**
     <https://github.com/civicrm/civicrm-core/blob/master/CRM/Member/xml/Menu/Member.xml#L13>
  
  <https://github.com/civicrm/civicrm-core/blob/master/CRM/Member/xml/Menu/Member.xml#L48>
  
  2. When above one of the 2 url is hit CiviCRM will execute run() function from [here](https://github.com/civicrm/civicrm-core/blob/master/CRM/Member/Page/Tab.php#L334). Where you decided which file to invoke for example to create view form process view(), Add/Edit process edit(), listing process browse()
  3. Each php file should have tpl associated with it.
  
  You can copy paste same file and structure and just change the class name. It should work for you.
  
  HTH
  
  Pradeep
  
  
  ---
  
  