Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » Redirection on query
Redirection on query
Redirection on query
Hi there, need help with this recipe. The purpose is if there is null in any of the field in cb it will redirect to a certain page (user page). It doesn't seem to work on my side. Kindly help me debug this please.
Code:
$user_id = $db->getEscaped((int)($user->id));
if ($user_id > 0) {
$query = "select * from jos_comprofiler where user_id = '$user_id';";
$db->setQuery( $query );
$row = $db->loadObject();
/* you can now get hold of state, phone, fax, website,
* location, or whatever else they enter. All optional fields
* like this get prefixed with "cb_" (see below).
*/
$firstname = $row->firstname;
$middlename = $row->middlename;
$lastname = $row->lastname;
$mobile = $row->cb_mobile;
$address = $row->cb_address;
$city = $row->cb_city;
$birthday = $row->cb_birthday;
$nickname = $row->cb_nickname;
$zipcode = $row->cb_zipcode;
$country = strtolower($row->cb_country); /* lower-case for easier comparisons */
$city = strtolower($row->cb_city);
$state = strtolower($row->cb_state);
// etc... add more variables depending on what fields are set up in CB.
// your rules: use any of the following and customise as required.
if ($user->middlename = null)
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
if ($user->nickname = null)
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
if ($user->mobile = null)
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
if ($user->address = null)
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
if ($user->city = null)
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
if ($user->province = null)
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
Re: Redirection on query
Hi hacksider,
I don't know if this is the problem, but there's a bug in my forum software that means every time you enter # __tablename (but without the space) it converts it to jos_tablename. But in Joomla 2.5+, the tables are not prefixed with jos_ any more. So with the code you pasted above, do you have it as jos_comprofiler or as # __comprofiler (but without the space)? It needs to be the one with the # in it. That could be the error.
The next thing is: what does actually happen when you use this code? Do you get any kind of redirection, even to the wrong page? Or does nothing happen at all?
If nothing happens at all, then you may need to ensure that the MetaMod is published, set to a valid module position, and assigned to some or all pages on the site. To test this, turn on Debug mode within MetaMod and ensure that on the pages where you want the test to appear you can actually see some output. No output means that the MetaMod itself is not executing on that page.
If that doesn't help, please get back to me and I'll look at it further.
Cheers,
Stephen
Re: Redirection on query
I enabled debug mode and it's showing
Code:
$option:com_content
$view: article
$id: 45
$Itemid: 269
$timezone: UTC
$language: en-us
$language_code: en
$language_region: us
Logged-in users only; found logged-in user.
Including modules: None
I also change it to
Code:
$user_id = $db->getEscaped((int)($user->id));
if ($user_id > 0) {
$query = "select * from #__comprofiler where user_id = '$user_id';";
$db->setQuery( $query );
$row = $db->loadObject();
/* you can now get hold of state, phone, fax, website,
* location, or whatever else they enter. All optional fields
* like this get prefixed with "cb_" (see below).
*/
$firstname = $row->firstname;
$middlename = $row->middlename;
$lastname = $row->lastname;
$mobile = $row->cb_mobile;
$address = $row->cb_address;
$city = $row->cb_city;
$birthday = $row->cb_birthday;
$nickname = $row->cb_nickname;
$zipcode = $row->cb_zipcode;
$country = strtolower($row->cb_country); /* lower-case for easier comparisons */
$city = strtolower($row->cb_city);
$state = strtolower($row->cb_state);
// etc... add more variables depending on what fields are set up in CB.
// your rules: use any of the following and customise as required.
if ($middlename == null)
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
if ($nickname == null)
$redirect("index.php?option=com_comprofiler&task=userdetails");
if ($mobile == null)
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
if ($address == null)
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
if ($city == null)
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
if ($province == null)
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
Still, only the debug but nothing else (no redirection).
By the way, I'm using joomla 3.2 on this.
Re: Redirection on query
I alro tried this but not successful still...
Code:
$user_id = $db->getEscaped((int)($user->id));
if ($user_id > 0) {
$query = "select * from #__comprofiler where user_id = '$user_id';";
$db->setQuery( $query );
$row = $db->loadObject();
/* you can now get hold of state, phone, fax, website,
* location, or whatever else they enter. All optional fields
* like this get prefixed with "cb_" (see below).
*/
$firstname = $row->firstname;
$middlename = $row->middlename;
$lastname = $row->lastname;
$mobile = $row->cb_mobile;
$address = $row->cb_address;
$city = $row->cb_city;
$birthday = $row->cb_birthday;
$nickname = $row->cb_nickname;
$zipcode = $row->cb_zipcode;
$country = strtolower($row->cb_country); /* lower-case for easier comparisons */
$city = strtolower($row->cb_city);
$state = strtolower($row->cb_state);
// etc... add more variables depending on what fields are set up in CB.
// your rules: use any of the following and customise as required.
if ($middlename == 'NULL')
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
if ($nickname == 'NULL')
$redirect("index.php?option=com_comprofiler&task=userdetails");
if ($mobile == 'NULL')
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
if ($address == 'NULL')
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
if ($city == 'NULL')
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
if ($province == 'NULL')
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
Re: Redirection on query
Oh by the way, I was just revisiting this post and noticed something: your code needs a trailing "}" in it. That's because the "if" statement is not closed.
So if you put this on a line by itself at the very end:
}
... and make sure that your null tests look like this:
if ($mobile == null)
$app->redirect("index.php?option=com_comprofiler&task=userdetails");
(i.e. not "NULL" but just null)
... then that at least gets rid of 2 of the reasons it may not be working.
Hope that helps,
Stephen
- Index
- » MetaMod
- » MetaMod General Support
- » Redirection on query
Board Info
- Board Stats:
- Total Topics:
- 1698
- Total Polls:
- 6
- Total Posts:
- 5944
- Posts this week:
- 4
- User Info:
- Total Users:
- 5544
- Newest User:
- odom3140505
- Members Online:
- 0
- Guests Online:
- 100
- Online:
- There are no members online
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked