Forums

Conditional enable/disable of a plugin?

a.carter 16 Sep, 2011
I have a form that on submission, stores the record in a seperate DB table and also creates a user using the CB Plugin. Great works well.

However, I have a question on that form made up of 2 radio buttons that says "Join Shop?" 1) YES 2) NO
This is why I use CB Plugin. If a user selects yes, jquery opens a div that has desired username, pass, and verifypass text boxes. The are validated to make sure there is a value in them. and they are mapped to CB fields using the plugin. Great. This works great. Users get created.

The problem is when a user selects no, theres a bit of javascript that turns the validation off so the form doesnt throw any errors & this doesnt open any extra divs, so the user never sees the username/pass/verifypass text boxes. Unfortunately, when I submit the form the CB plugin then throws an error because it needs username and password and verifypassword as they are required fields by CB.

Basically, what I would like it to is if user has selected no, then using some method (serverside validation maybe??) to disable the CB plugin on the form and not pass the data along to it. as it will give me username and password not supplied error?

I hope that makes sense?

I thought abuot using serverside validation and having the php do a sql query to update the enabled status of the plugin for that form, but I cant seem to find where in the DB it is flagged that CB plugin is enabled or disabled for that form. All I could find is what Chrono fields are mapped to which CB fields and to which form they are associated.

Any help/ideas/hacks would be greatly appreciated.
GreyHead 16 Sep, 2011
Hi a.carter,

This must be ChronoForms v3. There was never a good way of making plugins conditional :-(

There are a few ways to work around this.
[list=a]
  • You could hack the plugin code to check for some marker in the results.

  • You can conditionally redirect the user before the plugin runs use the On Submit After Code box and set the run order so that the plugins are last.

  • You can use more than one form and redirect the user to a second form depending on their choices in the first form. You can disguise the second form as a 'confirmation page' or you can use JavaScript to have it auto-submit.
  • [/list:o]

    Bob
    a.carter 17 Sep, 2011
    Hi Bob,

    Thanks for your response. Great ideas. I'm interested in a) and b), I don't really want to make separate forms or have a 2 step process.

    Hacking the plugin and having it check the POST value of the radio button name joinyesno, if it equals Y continue, if N exit plugin, is that what you're suggesting?

    As for b), could you please give me a little more detail in how that would be achieved?

    thanks.
    GreyHead 17 Sep, 2011
    Hi a.carter,

    Yes, that is what I am suggesting as a hack - that said, I don't recommend hacking the core code :-(

    The redirect route would use, for example $mainframe->redirect('some_url'); to redirect the user. This is a crude but effective way of stopping the ChronoForms procesing.

    Personally I'd probably use the two form method. It's usually possible to disguise the second from so that it seems a normal part of the flow and it definitely gives you better control.

    Bob
    a.carter 17 Sep, 2011
    Thanks for the tips again Bob.

    on a another note, does V4 have this capability?
    GreyHead 17 Sep, 2011
    Hi a.carter,

    Not specifically to enable/disable but there is the ability to create a conditional process flow: if this succeeds then do *this* else do *that*

    Bob
    This topic is locked and no more replies can be posted.