Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

PHP to check empty field

PHP to check empty field

I have chameleon running various processes on my Virtuemart including identifying which country the registered shopper is in and assigning them a chopper group

I need to do the following:
New user registers in Joomla
Chameleon grabs any registered user without a country in their VM Account
Chameleon redirects to VM Account page

I use the following code to show for Canada, how would I adjust it to show for "empty"
$vm = JomGenius("virtuemart"); // initialise object
if ( $vm->check( "billto_countryname = Canada" ) ) return true;

Something like this?
if ( $vm->check( "billto_countryname = 'empty'" ) ) return true;

metabern
Beginner Modder
ranks
useravatar
Offline
18 Posts
Administrator has disabled public posting

Re: PHP to check empty field

Hi,

to test for empty, you can use the 2nd argument for ->check() to store the thing you are comparing it to  - in this case an empty string.

$vm = JomGenius("virtuemart"); // initialise object
if ( $vm->check( "billto_countryname =","" ) ) return true;

Cheers
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: PHP to check empty field

Thanks for that, so I used the php you gave above and the rule works, however it creates a bizarre error/issue in VM Account page.

VM account page has two dropdowns for country and state/province region. They are interdependent; country choice triggers range of states in state/prov/region menu

When the Chameleon redirect is on, the dropdowns on VM Account page stop working. Country choice is available, but state choice isn't.

When Chameleon rule is unpublished, the VM account page works normally

Any thoughts on how I can resolve this?

metabern
Beginner Modder
ranks
useravatar
Offline
18 Posts
Administrator has disabled public posting

Re: PHP to check empty field

I wonder if there's a PHP warning/error being produced within the HTML of the dropdowns? Sometimes this can also happen during AJAX requests. If you're familiar with your web browser's debugger/Console (e.g. in Safari/Firefox/Chrome), please take a look for JS/HTML errors being reported, and take a look at the HTML of the page to see if there's anything wrong with the State choice dropdown HTML.

If that sounds like gobbledygook to you, I'll be happy to take a look at your site for you. In that case please send me a user login (if required), the URL, and the exact series of steps required to replicate the error.

Thanks
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: PHP to check empty field

Thanks for your thorough response. This is a copy paste from my Safari console after doing the following:

Load page
Chameleon detects the following in PHP option
$vm = JomGenius("virtuemart"); // initialise object
if ( $vm->check( "billto_countryname =","" ) ) return true;

If true Chameleon rule redirects to incomplete VM account page where user is required to add address to continue.

Chameleon rule functions correctly but upon arriving at the VM Account page the VM State/Province/County dropdown is broken.

If Chameleon is disabled and page is loaded normally, functionality returns

I have copy pasted the console info below.

If you'd like to get under the hood, will set you up with a Joomla account

Cheers





[Log] JQMIGRATE: Migrate is installed, version 1.4.1 (jquery-migrate.min.js, line 2)
[Log] Object (vmsite.js, line 86)

abort: function(a)

always: function()

complete: function()

done: function()

error: function()

fail: function()

getAllResponseHeaders: function()

getResponseHeader: function(a)

overrideMimeType: function(a)

pipe: function()

progress: function()

promise: function(a)

readyState: 4

responseText: "<!DOCTYPE html>↵<html lang=\"en-gb\" dir=\"ltr\" class=\"responsive com-virtuemart view-user layout-edit no-task itemid-669 version-1.5\">↵<head…"

setRequestHeader: function(a,b)

state: function()

status: 200

statusCode: function(a)

statusText: "OK"

success: function()

then: function()

Object Prototype

[Log] parsererror (vmsite.js, line 87)
[Log] SyntaxError: JSON Parse error: Unrecognized token '<' (vmsite.js, line 88)
parse
parseJSON — jquery.min.js:4:16652
parseJSON — jquery-migrate.min.js:2:3819
Xb — jquery.min.js:4:18961
y — jquery.min.js:4:22408
c — jquery.min.js:4:26927

> Selected Element
< <select aria-invalid="true" aria-required="true" class="required vm-chzn-select invalid" id="virtuemart_state_id_field" name="virtuemart_state_id" required="required">
<option value>…</option>
</select>

metabern
Beginner Modder
ranks
useravatar
Offline
18 Posts
Administrator has disabled public posting

Re: PHP to check empty field

Hi, thanks for that excellent info.
It looks like the AJAX call to index.php?option=com_virtuemart&view=state&format=json&virtuemart_country_id=223 is getting a PHP error/warning thrown, which is adding the extra "<" to the stream (along with the rest of the error).

Can you please look at the actual file being loaded by the URL above, in your browser's inspector, and see if you can find the warning/error being thrown?
In Safari, I "Show Web Inspector" then go to the Resources tab, load the problem page, then look at the "XHR" resources (all the AJAX calls). Click on the latest index.php in the list, and you should see the JSON response. If you chose USA, then this starts with:

{
    "223": [
        {
            "virtuemart_state_id": "1",
            "virtuemart_vendor_id": "1",
            "virtuemart_country_id": "223",
            "virtuemart_worldzone_id": "0",
            "state_name": "Alabama",
            "state_3_code": "ALA",
            "state_2_code": "AL",
            "ordering": "0",
            "shared": "1",
            "published": "1",
            "created_on": "0000-00-00 00:00:00",
            "created_by": "0",
            "modified_on": "0000-00-00 00:00:00",
            "modified_by": "0",
            "locked_on": "0000-00-00 00:00:00",
            "locked_by": "0"
        },

However in your case there will be an error somewhere...

In the Chrome inspector, you can find these by going into the Network tab, then click on XHR and look at the URLs in the list below. Click on index.php and the "Response" sub-tab, and you should see the response.

Hope that helps
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: PHP to check empty field

Hey there, the response is below:

I'm not sure how to proceed with this

Cheers

{"html":"<div class=\"vp-minicart\">\n\t<div class=\"vp-dropmod-container\">\n\t\t<div class=\"vp-dropmod-anchor btn-jewel-group\">\n\t\t\t<a href=\"\/ecom\/cantec-cart\" class=\"color-base empty\">\n\t\t\t\t<i class=\"fa fa-smart-cart-o fa-2x\"><\/i>\n\t\t\t<\/a>\n\t\t\t<div class=\"jewel jewel-top jewel-invert hide\">\n\t\t\t\t<span class=\"product-count\">0<\/span>\n\t\t\t<\/div>\n\t\t<\/div>\n\t\t<span class=\"mini-cart-total\">$0.00 USD<\/span>\n\t\t<div class=\"vp-dropmod-inner\">\n\t\t\t<div class=\"vp-dropmod-contents\">\n\t\t\t\t\t\t\t\t\t<div class=\"vp-dropmod-header empty\">\n\t\t\t\t\t\t<div class=\"row row-mini\">\n\t\t\t\t\t\t\t<div class=\"col-xs-12 align-center\">\n\t\t\t\t\t\t\t\tThere are no products in your cart.\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<div class=\"vp-dropmod-loader hide\"><div class=\"inner\"><\/div><\/div>\n\t\t\t<\/div>\t\n\t\t<\/div>\t\t\n\t<\/div>\n<\/div>\n\n"}

metabern
Beginner Modder
ranks
useravatar
Offline
18 Posts
Administrator has disabled public posting

Re: PHP to check empty field

Any feedback on what to do? I need to wrap this up and theres no other way to do it other than with a Chameleon redirect that breaks my VM form.

Thanks for all of your help so far.

Cheers

metabern
Beginner Modder
ranks
useravatar
Offline
18 Posts
Administrator has disabled public posting

Re: PHP to check empty field

Any thoughts? I've refined the issue a little:

Virtuemart Account Page state/province/region dropdown breaks whenever there is any kind of Chameleon redirect rule running on my site.

I thought it was an issue redirecting to account page, but when there is any redirect at all the issue persists

metabern
Beginner Modder
ranks
useravatar
Offline
18 Posts
Administrator has disabled public posting

Re: PHP to check empty field

Hi metabern,

the response you quoted looks perfectly legitimate, so that's not the problem.
Could you possibly send me a URL and login for your site so I can investigate the response more thoroughly? You can send it via IM, or you probably have my e-mail address.

Sorry for the delay - I have some more time to work on it over the next few days.
Best regards
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5913
Dormant:
User Info:
 
Total Users:
10727
Newest User:
solza2
Members Online:
0
Guests Online:
213

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