I use this code to redirect visitors to another url when a certain amount of people have subscribed my form:
This works fine. But is there a possibility to disable a specified field (e.g. 'datum') in my form instead of redirecting to another url?
I found this code from Bob:
But I don't understand on how to do so.
<?php
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(*)
FROM `#__my_table` ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count >= 15 ) {
// Redirect to my url
$app =& JFactory::getApplication();
$app->redirect('my_url');
}
?>
This works fine. But is there a possibility to disable a specified field (e.g. 'datum') in my form instead of redirecting to another url?
I found this code from Bob:
<?php
$db =& JFactory::getDBO();
$query = "
SELECT COUNT
FROM `#__some_table`
WHERE `course_id` = 'xxx' ;
";
$db->setQuery($query);
$count = $db->loadResult();
$form->data['open'] = false;
If ( $count < 999 ) {
$form->data['open'] = true;
}
?>
Then you can use $form->data['open'] to manage the form display.
But I don't understand on how to do so.
Hi geertmartens,
You could just add some JavaScript from a Load JS action:
Bob
You could just add some JavaScript from a Load JS action:
jQuery(document).ready(function (jQ) {
<?php
if ( $form->data['open'] ) {
echo "jQ('#date_id').prop('disabled', false);";
} else {
echo "jQ('#date_id').prop('disabled', true);";
}
?>
});
Bob
This works Bob!
Is there also the possibility to change the value of 'date_id'?
E.g.:
Say that:
results in the value: " 16/09/2015 "
And I want it to result in the value: " 16/09/2015 (Full) "
Is this possible?
Is there also the possibility to change the value of 'date_id'?
E.g.:
Say that:
echo "jQ('#date_id').prop('disabled', true);";
results in the value: " 16/09/2015 "
And I want it to result in the value: " 16/09/2015 (Full) "
Is this possible?
Hi geertmartens,
You can do that back in the original code
Bob
You can do that back in the original code
. . .
if ( $count < 999 ) {
$form->data['open'] = true;
} else {
$form->data['date_id'] += ' (full)';
}
?>
Bob
Thanks Bob.
I used this code:
And replaced it with this:
But that results in the same value: " 16/09/2015 " and not " 16/09/2015 (full) ".
What am I doing wrong?
I used this code:
<?php
$db =& JFactory::getDBO();
$query = "
SELECT SUM(`aantal`)
FROM `my_table`
WHERE `datum` = 'my_value' ;
";
$db->setQuery($query);
$count = $db->loadResult();
$form->data['open'] = false;
If ( $count <= 15 ) {
$form->data['open'] = true;
}
?>
And replaced it with this:
<?php
$db =& JFactory::getDBO();
$query = "
SELECT SUM(`aantal`)
FROM `my_table`
WHERE `datum` = 'my_value' ;
";
$db->setQuery($query);
$count = $db->loadResult();
$form->data['open'] = false;
If ( $count <= 15 ) {
$form->data['open'] = true;
} else {
$form->data['datum'] += ' (full)';
}
?>
But that results in the same value: " 16/09/2015 " and not " 16/09/2015 (full) ".
What am I doing wrong?
Hi geertmartens,
No idea - the code looks OK. Please try adding a Debugger after the Custom Code and see if the value of datum has actually changed.
Bob
No idea - the code looks OK. Please try adding a Debugger after the Custom Code and see if the value of datum has actually changed.
Bob
Hi Bob
The only thing I can see in the debugger is:
The only thing I can see in the debugger is:
Array
(
[option] => com_chronoforms5
[chronoform] => TESTform
[com_twojtoolbox_filelist_css] => Array
(
)
[com_twojtoolbox_filelist_js] => Array
(
)
[com_twojtoolbox_filelist_less] => Array
(
)
[open] => 1
[datum] => 0
)
This topic is locked and no more replies can be posted.