Use validation or re-direct form pluguin --> using a radiobutton element

javier94

Member
hello,

i have a radiobutton element, named "activar".. with 2 options... yes or not. .so the user must to say one of both options...

if user have 3 registers with "yes" the suscription is ok.. but if user wants one more register the "4" register.. the user must to upgrade to a different suscription.

i have try with the Re-direct plugin form ( so redirects to the upgrade suscriptions plans page)

the trouble is.. if the user go to upgrade suscriptions page, but will not do nothing and turn back to the
form.. the "4" register is added, but the user didn´t make the upgrade...

Once we saved the form.. using the plugin i can not control what the user makes.. and the new register is saved, allowed to the suscriber, work without make the upgrade.

so this option is not working well.

Now, I'm trying use the radio button, but giving a php validation...

1.- i check for the suscriber type
2.- when i know the suscriber --> check how many registers are allowed
3.- if the registers are ok -- suscriber continues.. if are not ok.. should make an upgrade.(go to an article)

the code use is:

$uid = '{cartas_registro___user_id}';

$db = JFactory::getDbo();

/// Contamos registros a Sí
$query1 = $db
->getQuery(true)
->select('COUNT(*)')
->from($db->quoteName('cartas_registro'))
->where($db->quoteName('check_1') . " = 1")
->where($db->quoteName('user_id') . " = " . $uid);
// Reset the query using our newly populated query object.
$db->setQuery($query1);
$count = $db->loadResult();

/// Cogemos plan_id de la fecha del último plan suscrito
$query = $db->getQuery(true);
$query->select($db->quoteName(array('plan_subscription_status','plan_subscription_to_date','plan_id','user_id', 'first_name', 'published'))); //published - 1 activo - 0 no es activo
$query->from($db->quoteName('w47fa_osmembership_subscribers'));
$query->where($db->quoteName('user_id') . ' = ' . $uid);
$query->order($db->quoteName('plan_subscription_to_date') . ' DESC');
$db->setQuery($query);
//$row = $db->loadResult();
$row = $db->loadAssoc();
//var_dump("A Sí tenemos: " . $count . " - " . $row['plan_subscription_to_date'] . " - " . $row['plan_id']);
//exit();
$plan = $row['plan_id'];
if($row['published'] == 0){
return true;
} else {
switch ($plan) {
case 1:
if ($count <= 3){
return false;
} else {
return true;
}
break;
case 2:
if ($count <= 6){
return false;
} else {
return true;
}
break;
case 3:
if ($count <= 15){
return false;
} else {
return true;
}
break;
default:
return true;
}
}

=============

Is possible add a re-direct inside this code.. and if the validation is not ok.. go to this page

(https://qrmenudigital.com/index.php?option=com_content&view=article&layout=edit&id=56)

Which would be the best way to re-direct to the article use the validation???

Any suggestion??

thanks

Javier
 
It is obvious that the subscription status should be updated after the user has actually made the upgrade. You mentioned that the subscription is made in an article. How is that exactly done?

If the user would make the upgrade in a Fabrik form, you could update the upgrade status with form php-plugin after the upgrade is actually made by the user.
 
I'm using a component to make the subscriptions.. because the user must to pay.. so this component.. allows upgrade the suscription and allows to make the payment.. component is Membership Pro.

how it works:

i have 3 subscriptions ( so the user create using fabrik a Restaurant Menu in differents languages (5), depending of languages use the restaurant.. they buy , one subscription or other)

Basic - allow 3 registers
Gold - allow 6 registers
Platinum - allow 15 registers

I have a list.. is an activation page (fabrik) for the users.. so the user enter in this page.. and "activate" the numbers of registers they want to show to the restaurante customers.. each register is a different menu.. Daily Menu, Season Menu, Kids Menu, Wine List, Cocktails List, etc...

the idea is... ( i think we have 2 options) using a form plugin, or use the validation element. but not sure whick is best way. i'm testing both..

in the ACTIVATION LIST.. the user.. activate the registers.. using a radiobutton... only have to check in "yes" or "not" to activate or not activate --> activate means show this Menu.

What we need.

I need when the user activate the radio button the following..

check the user_id, once we have the user_id --> go to membership pro table --> to check with susbscription have this user_id

once we know the subscription of the user.. for example BASIC -- > we know this user only can Activate 3 registers --- in the moment the user try to activate the register "4" that is not allowed due their suscription.. the user should re-direct to artice... (https://qrmenudigital.com/index.php?option=com_content&view=article&layout=edit&id=56) is a joomla article where the user will find a button to go to the "upgrade" page from membership Pro.. where the user pay the new suscription upgrade.

Till here ... everything is ok.

The trouble is..

If use the validation element in the radio button --> i'm not sure if after the code checking.. i can make a re-direct to the article.. i have to add the code to the validation php but i'm not sure how to make the re-direct...

If i use the Form plugin, using a re-direct action.. is working.. but not in the right way..

the user activate the register, save the form, go the upgrade membership pro page --> but if the user will not finish and make the payment... and for example turn back to the activation page
in the page the "4" register is ACTIVATE ---> when must be NOT ACTIVATE.


So maybe, instead using a form plugin with re-direct, i should try with PHP, on before process, and see if the register is activate or not first.. and after make the re-direct using code..

i think is the best option..

Do you know if validation element--- allow make a re-direct too?

thanks

Javier
 
Try with Joomla's redirect (I didn't test)
$myapp = JFactory::getApplication();
$myapp->redirect("some URL", "Some system message");
 
If I understand correct, you do not want the "register" record to be added to database if the user doesn't have the sufficient subscription plan. So why not inform the user already when he/she opens the form? Like a message "You do not have any registers left, please upgrade your subscription plan by clicking here..." in the form header.

PHP plugin onLoad you should be able to check the subscription status and display a message like:
$formModel->setFormErrorMsg("You do not have any registers left...");
or use Joomla system message:
$msg = 'You do not have any registers left...';
JFactory::getApplication()->enqueueMessage($msg, 'message');

Otherwise user fills in a long form and only then realizes that he/she doesn't have the proper subscription plan when the form validation fails. And maybe doesn't even want to upgrade.
 
Last edited:
is a good option inform when the form load...
I had not thought of it..
i'm gonna try this option

thanks!

Javier
 
SOLVED.

after try the form plugin, and the validation code.. with the validation code is working.. also i can make the re-direct, adding a link in the error message box

The code in the radio button element validation is:

$uid = $user = JFactory::getuser();
$ui = $user->id;
//echo "User ID:" . $ui;
//var_dump(); exit;

$db = JFactory::getDbo();

/// Contamos registros a Sí
$query1 = $db
->getQuery(true)
->select('COUNT(*)')
->from($db->quoteName('cartas_registro'))
->where($db->quoteName('check_1') . " = 1")
->where($db->quoteName('user_id') . " = " . $ui);
// Reset the query using our newly populated query object.
$db->setQuery($query1);
$count = $db->loadResult();

//echo "Cartas Activadas: " . $count . " para usuario: " . $ui;
//var_dump(); exit;


/// Cogemos plan_id de la fecha del último plan suscrito
$query = $db->getQuery(true);
$query->select($db->quoteName(array('plan_subscription_status','plan_subscription_to_date','plan_id','user_id', 'first_name', 'published'))); //published - 1 activo - 0 no es activo
$query->from($db->quoteName('w47fa_osmembership_subscribers'));
$query->where($db->quoteName('user_id') . ' = ' . $ui);
$query->order($db->quoteName('plan_subscription_to_date') . ' DESC');
$db->setQuery($query);
//$row = $db->loadResult();
$row = $db->loadAssoc();

//var_dump("A Sí tenemos: " . $count . " - " . $row['plan_subscription_to_date'] . " - " . $row['plan_id']);
//exit();

$plan = $row['plan_id'];
if($row['published'] == 0){
return true;
} else {
switch ($plan) {
case 1:
if ($count < 3){
//$formModel->setFormErrorMsg("Ahora tienes " . $count . " activados");
//echo "Ahora tienes " . $count . " activados";
//var_dump(); exit();
return false;
//return true;
} else {
//echo "Ahora tienes " . $count . " de " . 3 . " activados";
//var_dump(); exit();
//$formModel->setFormErrorMsg("Ahora tienes " . 3 - $count . " activados");
return true;
//return false;
}
break;
case 2:
if ($count < 6){
return false;
} else {
return true;
}
break;
case 3:
if ($count < 15){
return false;
} else {
return true;
}
break;
default:
return true;
}
}

and in the message error.. I add a link with the re-direct

Límite de activaciones <a href="https://qrmenudigital.com/index.php?option=com_content&view=article&layout=edit&id=56"> <font color= "#0000FF"> HAZ CLICK AQUÍ</font></a>

so when the user try to move the radiobutton to YES.. and have pass the limit of registers --> validation code.. show the Error message.. with the link --> so can go to the error page --> and after to the subscription page..

Many thanks !!

Javier
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top