We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34193
    • 330 Posts
    I’m trying to set up a custom hook for FormIt, at the momment the snippet does nothing but returns a message via an error just to see if it was running, but that message is not being displayed below is my form code and my snippet
    [[FormIt? &hooks=`addpupil`]]
    
    <h2>Add Primary Contact</h2>
    
    [[!+fi.error.error_message:notempty=`<p>[[!+fi.error.error_message]]</p>`]]
    
    <form action="[[~[[*id]]]]" method="post" class="form">
    <label for="title">
            Title:
            <span class="error">[[+fi.error.title]]</span>
        </label>
        <select name="title" value="[[+fi.title]]">
            <option value="Mr" [[!+fi.title:FormItIsSelected=`Mr`]] >Mr</option>
            <option value="Mrs" [[!+fi.title:FormItIsSelected=`Mrs`]] >Mrs</option>
            <option value="Miss" [[!+fi.title:FormItIsSelected=`Miss`]] >Miss</option>
        </select>
    
        <label for="firstname">
            Firstname:
            <span class="error">[[+fi.error.firstname]]</span>
        </label>
        <input type="text" name="firstname" id="firstname" value="[[+fi.firstname]]" />
    
        <label for="surname">
            Surname:
            <span class="error">[[+fi.error.surname]]</span>
        </label>
        <input type="text" name="surname" id="surname" value="[[+fi.surname]]" />
    
        <br />
    <br />
        <label for="address">
            Address:
            <span class="error">[[+fi.error.address1]]</span>
            <span class="error">[[+fi.error.address2]]</span>
            <span class="error">[[+fi.error.address3]]</span>
        </label>
        <div style="text-align: left; width:225px;">
        <input style="width:241px;" type="text" name="address1" id="address1" value="[[+fi.address1]]" /><br />
        <input style="width:241px;" type="text" name="address2" id="address2" value="[[+fi.address2]]" /><br />
        <input style="width:241px;" type="text" name="address3" id="address3" value="[[+fi.address3]]" />
        </div>
        <label for="postcode">
            Post Code: 
            <span class="error">[[+fi.error.postcode]]</span>
        </label>
        <input type="text" name="postcode" id="postcode" value="[[+fi.postcode]]" />
    
    <br />
    <br />
    
        <label for="phonenum">
            Landline Number:
            <span class="error">[[+fi.error.phonenum]]</span>
        </label>
        <input type="text" name="phonenum" id="phonenum" value="[[+fi.phonenum]]" />
        <label for="mobilenum">
            Mobile Number:
            <span class="error">[[+fi.error.mobilenum]]</span>
        </label>
        <input type="text" name="mobilenum" id="mobilenum" value="[[+fi.mobilenum]]" />
    <label for="email">
            Email Address:
            <span class="error">[[+fi.error.email]]</span>
        </label>
        <input type="text" name="email" id="email" value="[[+fi.email]]" />
    <br />
    
    
    
        <br class="clear" />
        [[!+formit.recaptcha_html]]
        [[!+fi.error.recaptcha]]
    
        <br class="clear" />
    
        <div class="form-buttons">
            <input type="submit" value="Add Parent" />
        </div>
    </form>

    <?php
    $errorMsg = 'snippet run';
    $hook->addError('error_message',$errorMsg);
    return false;


    Most of this has been grabbed and edited from the RTFM entries for FormIt. Any suggestions as to why the message is not being shown.
      • 4172
      • 5,888 Posts
      Did you try to call formit uncached?

      [[!FormIt? &hooks=`addpupil`]]
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 34193
        • 330 Posts
        Thanks i’d been clearing the cache on each try but not running it uncached. So looks like FormIt needs to run uncached to deal with custom hooks.