We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 42967
    • 143 Posts
    Hi,

    I am trying to change a formit parameter based on a checkbox selection, is this something I need a custom hook to do?

    [[!FormIt? &hooks=`successMessage,spam,mChimpXSubscribe`
      &validate=`email:email:required`
      &mcApiKey=`123`
      &mcListId=`[[!+fi.list]]`
      &mcFailOnApiKey=`1`
      &mcDoubleOptin =`0`
      &mcFailOnListNotExists=`1`
      &mcFailOnMissingRequired=`1`
      &mcFailOnNotSubscribed=`1`
      &successMessage=`Subscription successful, thank you`
      &mcFailOnAlreadySubscribed=`1`
    ]]
    
    <form action="[[~[[*id]]]]" method="post" id="mailingList">
    
        <input type="hidden" name="nospam:blank" value="" />
        <input type="text" class="[[!+fi.error.email:notempty=`fieldError`]]"  name="email" id="email" value="[[+fi.email:default=`[email protected]`]]"/>
      
      <select name="list">
    <option value="123455666" [[!+fi.list:FormItIsSelected=`123455666`]]>trade</option>
    <option value="123455646" [[!+fi.list:FormItIsSelected=`123455646`]]>not trade</option>
    </select>
      
      <input type="submit" class="submit"  value="Join" />
    
    </form>
    <p class="formStatus">
    
    [[!+fi.addressTo]]
    [[!+fi.error.email]]
    [[!+fi.error_message:notempty=`[[!+fi.error_message]]`]]
    [[!+fi.successMessage:notempty=`[[!+fi.successMessage]]`]]
    </p>
    
    [ed. note: eighthday last edited this post 10 years, 10 months ago.]
      Eighth day design
      Design agency with offices in Edinburgh and Brighton
    • Yes, you'll need to do that in a hook. [[!+fi.list]] is parsed before the outer [[!FormIt]] call is.

      If I remember correctly, you can use something along these lines in a hook:

      $value = $hook->getValue('foobar');
      
      if ($value == 'baz') {
        $hook->formit->config['mcListId'] = $value;
      }
      
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.