Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Two forms, each display 50% of the time
I have a requirement to display the output of a Textpattern form 50% of the time. There are two forms – each would display half the time.
This may be an easy one, but an obvious Textpattern tag hasn’t yet occurred to me.
Ideas?
Offline
Re: Two forms, each display 50% of the time
You should precise what half the time means: randomly with 1/2 probability (easy), or alternatively. In the latter case, should it be per user (more tricky)?
Offline
Re: Two forms, each display 50% of the time
The “easy” path will be fine.
Offline
Re: Two forms, each display 50% of the time
towndock wrote #331426:
The “easy” path will be fine.
Then you create, say, form1
and form2
and call
<txp:output_form form='form<txp:php>echo rand(1,2);</txp:php>' />
This should call each one half of time in average.
Edit: and if you need to name the forms differently, this should do:
<txp:variable name="form" trim>
<txp:php>
$forms = ['first_form', 'second_form'];
echo $forms[rand(0,1)];
</txp:php>
</txp:variable>
<txp:output_form form='<txp:variable name="form" />' />
Offline
Re: Two forms, each display 50% of the time
Sweet. Thank you, I’ll be trying this out tomorrow.
Offline
Offline