0

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.

1 Answer 1

2

Paul B,

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

  1. When above one of the 2 url is hit CiviCRM will execute run() function from here. Where you decided which file to invoke for example to create view form process view(), Add/Edit process edit(), listing process browse()

  2. 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.