Is there a way to limit how many checkboxes can be checked in Powermail form (Typo3 v7)?
We have to write our own validator. Typo3 add some variables within name attribute and this variable has to be read out. It looks like this:
name="tx_powermail_pi1[field][variable][]
Below an example with jquery.
$("input[name*='variable']").change(function(){
var max= 3;
if( $("input[name*='variable']:checked").length == max ){
$("input[name*='variable']").attr('disabled', 'disabled');
$("input[name*='variable']:checked").removeAttr('disabled');
}else{
$("input[name*='variable']").removeAttr('disabled');
}
});
More info https://docs.typo3.org/typo3cms/extensions/powermail/ForDevelopers/WriteOwnValidators/Index.html
Related
In the TYPO3 CMS 9.5.18 LTS with tx_news 8.3.0 we use the following extension Typoscript:
plugin.tx_news.settings{
# what is allowed to overwrite with TS
overrideFlexformSettingsIfEmpty := addToList(categories)
overrideFlexformSettingsIfEmpty := addToList(categoryConjunction)
# ids of categories
categories = 3
# category conjunction mode
categoryConjunction = or
}
I wonder why I have to add categories to overrideFlexformSettingsIfEmpty to get the result below. Never the less this post is more about how to achieve that the prev/next links (settings.detail.showPrevNext) does respect the category definition at all.
Our customer has 3 categories for news. If I go to a single page that does has a one category limitation (for the detail and the list page) I still e.g. can go "forward" to newer news in a total different category. However the list page only shows the news of that one selected category.
<f:if condition="{paginated.prev}">
<n:link newsItem="{paginated.prev}" settings="{settings}" class="ts-prev">
{paginated.prev.title}
</n:link>
</f:if>
Wasn't that never the case? Do I have to add some Typoscript or make a change in Fluid? The original code uses this settings variable as argument which contains the category limitation.
Okay I've had a look into the GeorgRinger\News\ViewHelpers\SimplePrevNextViewHelper and there aren't any limitation for the current chosen categories.
So here is what I did:
register a new optional argument categories to the viewhelper
add categories="{settings.categories}" to the simplePrevNext tag in the Detail.html
add an 'extra where' for the main query in the getNeighbours function
add the content for the additional where ( I did that first in the getNeighbours function )
Extra where:
if( is_array($newsOfCategory) && count($newsOfCategory) > 0 ){
$extraWhere[] = $queryBuilder->expr()->in('uid', $queryBuilder->createNamedParameter($newsOfCategory, Connection::PARAM_INT_ARRAY));
}
Content for the additional where:
if( is_string($categories) && preg_match('/^[0-9]+(,[0-9]+)*$/',$categories) ){
$categories = explode(',', $categories);
$tmpCon = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_category_record_mm');
$tmpQB = $tmpCon->createQueryBuilder();
$rows = $tmpQB
->select('uid_foreign')
->from('sys_category_record_mm')
->where(
$tmpQB->expr()->in('uid_local', $tmpQB->createNamedParameter($categories, Connection::PARAM_INT_ARRAY))
)
->andWhere(
$tmpQB->expr()->like('tablenames', $tmpQB->createNamedParameter('tx_news_domain_model_news'))
)
->execute()->fetchAll();
if( is_array($rows) && count($rows) > 0 ){
foreach($rows as $row){
$newsOfCategory[] = $row['uid_foreign'];
}
}
}
May be someone can use that in the future or the will integrate that to the repository.
I've created a small application form for my website. Everything works fine.
In the plugin settings there is a field called "Bodytext for Email to Receiver". This is the the mail I get, everytime somebody fills out an application form. It looks like this right now:
New application arrived!
{powermail_all}
Is it possible to get the Page UID from the application form into a variable to put it in there?
The only solutions I've found need TypoScript. Is there any other way?
The solution with typoscript should be (according to manual):
use in template:
{f:cObject(typoscriptObjectPath:'lib.pageuid')}
define the typoscript:
lib.pageuid = TEXT
lib.pageuid.data = page:uid
I'm not sure about an additional variable for {powermail_all} as I'm not familiar with the extension.
If I understand the manual correctly this might be possible with :
plugin.tx_powermail {
settings {
setup {
manipulateVariablesInPowermailAllMarker {
// possible sections (define for each, where you need it):
// confirmationPage, submitPage, receiverMail, senderMail, optinMail
submitPage {
pageUid = TEXT
pageUid.data = page:uid
}
senderMail {
pageUid = TEXT
pageUid.data = page:uid
}
}
}
}
}
I'm using the extension seo_dynamic_tag, which is a fantastic plugin for TYPO3 SEO purposes.
It uses registers to store the generated meta description and keywords. Later on in the script, the page metadata is filled in from these registers:
page {
meta {
description {
field >
data = register:description
}
keywords {
field >
data = register:keywordss
}
}
1000 < temp.seo
}
So far it works like charm.
But in addition I'd like to display a TEXT object on the page with the meta description on the bottom. The text should read the meta description and some other stuff. That's where I need your help.
I tried to do the "magic" like this:
temp.description = COA
temp.description {
10 = TEXT
10.value = Meta description: {register:description}
stdWrap.insertData = 1
}
lib.footer < temp.description
This simply does not work. If I want to display something else, for example {page:title} or {date:y-m-d}, data insertion works. For register:xxx it doesn't.
I already spent lots of hours to google out my desired solution, but no success :(
Do you have any idea what I'm missing here?
I'm using TYPO3 4.5.3 (I know I should update ;)).
Many thanks in advance for your help! :)
Your stdWrap.insertData = 1 is applied to your COA-object, and not to your TEXT-object. You can instead set 10.insertData = 1 or just write the following:
10 = TEXT
10.data = register:description
Is it possible to auto generate a mixed string of digits and letters by TypoScript, e.g. 12A54 or something similar?
I'd prefer a userFunc to a php include script. For example, you can pass parameters to a user function.
Typoscript:
includeLibs.generateInvoiceNo= fileadmin/scripts/generateInvoiceNo.php
temp.invoiceNo = USER
temp.invoiceNo {
userFunc =user_generateInvoiceNo->main
}
PHP:
fileadmin/scripts/generateInvoiceNo.php
<?
class user_generateInvoiceNo {
var $cObj;// The backReference to the mother cObj object set at call time
/**
* Call it from a USER cObject with 'userFunc = user_generateInvoiceNo->main'
*/
function main($content,$conf){
$length = 6;
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$number=substr(str_shuffle($chars),0,$length);
return $number;
}
}
?>
Credits:
This php script
TYPO3 Wizard on userFunc
As already mentioned, there is no such functionality in Typoscript and so the preferred method is to use some simle PHP function as suggested in other answers.
However, there is a cheat and that would be to use MySQL. Mind you, that it's a solution only if you absolutely cannot (for a reason that I really cannot think of) write a piece of custom PHP. Take it rather as an academic answer than a practical one.
temp.random = CONTENT
temp.random {
table = tt_content
select {
pidInList = 1
recursive = 99
max = 1
selectFields = SUBSTRING(MD5(RAND()) FROM 1 FOR 6) AS random_string
}
renderObj = TEXT
renderObj {
field = random_string
case = upper
}
}
NOTES:
pidInList must point to an existing page.
The MySQL command is really just an example as the string would never contain letters G-Z. I'm sure it's possible to come up with a better string generated by MySQL.
Patching TYPO3 sources for such easy tasks is wrong idea. After the next source upgrade you'll lose your changes.
Instead it's better to include an easy PHP script where you can render what you need check TSREF
Im building a newsletter and the start is like this:
DEAR ###USER_gender### ###USER_first_name### ###USER_last_name###
which outpouts
DEAR ###USER_gender### JOHN DOE
and I was hoping it would replace the gender mark with "Miss" and "Sir", depending on the value. How could I do this?
Extra fields have to be added to the field list (see docu). But I'm not sure whether this automatically works with non-string fields. Maybe using a hook is your solution or using another extension which adds a new field to tt_address.
Another solution is to nest marker:
###GENDER_###USER_gender######
and then warp you content in a new template object:
10 = TEMPLATE
10 {
template < yourAlreadyProcessedContent
marks {
GENDER_m = TEXT
GENDER_m.value = Sir
}
}
It's a bit unusual, but sometimes it's very useful.
(Personally I use it to replace version numbers in tt_content records.)
Edit:
Example for Dbugger:
Download the Introduction Package and install it. After that add to the Welcome page a new template record with the following steup:
temp.mainTemplate = TEMPLATE
temp.mainTemplate {
template = TEXT
template.value = (
Foo
###CONTENT###
###CONTENT###
Bar
)
subparts {
CONTENT < styles.content.get
}
}
page = PAGE
page {
typeNum = 0
10 = TEMPLATE
10 {
template < temp.mainTemplate
marks {
TEST = TEXT
TEST.value = ok
}
}
Now include CSS Styled Contnet and enable the following options:
clear constants, clear setup, rootlevel
The output should look like that:
Foo
Congratulations ...
Bar
If you add ###TEST### to the the tt_content record on the welcome page it will be replaced with ok.
This should work with direct mail, too.
Edit:
I'm sorry, this only works which normal extension which are use in the rendering process.
a little bit late, but here's the best solution for the salutation in direct_mail & tt_address .. works perfect for me. The personalized marker is just ###USER_salutation###,
https://blog.webentwickler.at/individuelle-marker-in-direct-mail/