Jump to content

Developer Documentation

core/ContactUs

What it is

A ContactUs extension is designed to allow you to handle contact form submissions in a special manner (based on the administrator configuration). For example, Commerce uses a ContactUs form extension to allow administrators to send contact form submissions to a support request (rather than emailing the administrator).

How it works

The extension has 3 methods defined.

    /**
     * Process Form
     *
     * @param    \IPS\Helpers\Form        $form        The form
     * @param    array                   $formFields Additional Configuration Formfields
     * @param    array                   $options    Type Radio Form Options
     * @param    array                   $toggles    Type Radio Form Toggles
     * @param    array                   $disabled   Type Radio Form Disabled Options
     * @return    void
     */
    public function process( &$form, &$formFields, &$options, &$toggles, &$disabled )
    {
    }

The process() method is called when an administrator attempts to configure the contact us form within the AdminCP. You can us this method to return additional form fields, and even adjust existing form field toggles. The form field keys must be setting keys within the internal settings system, as the form submission simply calls $form->saveAsSettings() afterwards. You should add your options to the $options array (passed by reference), and then add any additional configuration form field helper objects to the $formFields array. You can adjust the $disabled and $toggles arrays if appropriate (for instance, if there are no Support departments in Commerce, the option to submit contact us form submissions as a support request will be shown, but disabled).

    /**
     * Allows extensions to do something before the form is shown... e.g. add your own custom fields, or redirect the page
     *
     * @param    \IPS\Helpers\Form        $form        The form
     * @return    void
     */
    public function runBeforeFormOutput( &$form )
    {

    }

If your contact us form submission must do anything special when your extension is used (for instance, add extra form fields to the page or redirect to a different page) you can perform that work in runBeforeFormOutput().

    /**
     * Handle the Form
     *
     * @param    array                   $values     Values from form
     * @return    bool
     */
    public function handleForm( $values )
    {
        return false;
    }

When the contact us form is submitted by an end user, handleForm() will be called for each extension. You should confirm if your extension is configured to be used (e.g. by checking a setting property that was set from process() previously) and then perform whatever action your extension needs to perform. If your extension has handled the form submission, you should return TRUE from handleForm(), otherwise you should return FALSE so that other extensions will be processed.


  Report Document


×
×
  • Create New...