Creating a link to a .php page with the member's email and if it has a subscription add some codename to the link too.

I need to create an application in PHP but it needs some user details. So I was hoping I could use Velo to create a link to a page and attach to it the email and if the user has a subscription attach some codename. EG:

somedomain . com / frontend /callback.php?useremail@gmail.com&cd=888

Where cd=888 could be cd=222 if no subscription is found. Or something random but that I could read back and know what it is in code. The codename could also be encrypted with md5 or something that I change daily.

Another idea would be to create a Cookie, but from what I could read that’s not possible. :frowning:

Thanks guys!

Something like this?

import wixLocation from 'wix-location';

function goToPHP() {
    let emailvar = "me@gmail.com";
    let cd="888";
    
    // setup url
    let urlString = "?email="+emailvar  + 
                    "&cd="+ cdvar;
    
    let urllnk = "somedomain.com/frontend/callback.php"+urlString;
    console.log('Url Link: '+urllnk);
    // connect to external link
    wixLocation.to(urllnk);
}

Hi William,

First of all, why PHP? You have native solutions that works on Wix.

Thanks guys. I’m still learning how Wix code works. What I want to create is a page where users can select products from a list but also have this list populated by an Application (Windows EXE). That’s why I wonder if maybe PHP would be best, as I’m an advanced PHP coder already. :wink:

Cheers

I always thought that PHP is like PHYTON → absolutely incompatible in usage with wix.

Correct me if i am wrong, but if you want to work on wix → your task will be to get a great JS-Coder.

I got the code working, but it doesn’t change the link when using onMouseIn() or onReady(). The help says I can’t do this way, so I guess I need to setup the link before things are added to the screen. But I can’t figure what call is that, like onLoad() or setup()… Thanks again. Cheers!

Can you show your code, and explain a bit better when the link should be created. I’m also assuming you have something (object, button, etc), firing events, and you want something done when it fires. Is the link attached to a button?

I have dynamically changed the link on the page, depending on selections that were made on a form on the page. You can just connect it to a button called ‘SUBMIT’, and then setup an onClick() event for the button. From there you can create/adjust the urlString as you see fit, and then jump to the urL.

So you want to embed that page into your desktop application?

Here’s the code. It works now, as I set the button to an anchor and used the onClick, not sure if it’s the best way to do, but it works. Just the email is not been populated and I don’t know why.

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
//
export function button1_click(event)
{
  let user = wixUsers.currentUser;
  let emailvar = "";
  let isLoggedIn = user.loggedIn;
  let cdx="888";
  //
  user.getEmail().then( (email) => { emailvar = email; } );
  //
  let urlString = "?email="+emailvar + "&cd="+ cdx + "&l="+isLoggedIn;
  let urllnk = "https : // www. somedomain. com/frontend/callback.php"+urlString;
  wixLocation.to(urllnk);
}

@guikalfelz Hello, I’m wondering if you are not getting the result
due to you not waiting for the promise to return. Try these changes:

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';

//
export async function button1_click(event){
    let user = wixUsers.currentUser;
    let emailvar = "";
    let isLoggedIn = user.loggedIn;
    let cdx="888";
    //
    emailvar = await user.getEmail()
                   .then( (email) => { 
                       console.log("The email address returned from getEmail was: "+email);
                       return email;
                   })
                   .catch( (err) => {
                       console.log("Error occurred fetching email address.\n"+err);
                       return "";
                   });
    //
    let urlString = "?email="+emailvar + "&cd="+ cdx + "&l="+isLoggedIn;
    let urllnk = "https://www.somedomain.com/frontendcallback.php"+urlString;wixLocation.to(urllnk);}

@pekrzyz The code below is working correctly. I get the right email address now. But I will check yours too, so I can learn how it works. :slight_smile: <3

import wixLocation from ‘wix-location’ ;
import wixUsers from ‘wix-users’ ;
let userEmail = “none” ;
let isLogged = false ;
//
$w . onReady (() => {
let user = wixUsers . currentUser ;
isLogged = user . loggedIn ;
let email = user . getEmail (). then (( email ) => { userEmail = email ; });
});
//
export function button1_click ( event )
{
let cdx = “888” ;
let urlString = “?email=” + userEmail + “&cd=” + cdx + “&l=” + isLogged ;
let urllnk = “https: // www. somedomain. com/frontend/callback.php” + urlString ;
wixLocation . to ( urllnk );
}

@guikalfelz I see what you did. You moved the variables to the top of the module, so the scope of the variables have access to all functions/methods in the module. You also retrieved the email and saved the results as soon as the form loaded. Since getting the email was the last thing you did in the onReady function, there was nothing immediately depending on the data being returned by the promise from user.getEmail. So if it took a little longer for the data to return from getEmail and be saved into the variable, it didn’t matter, because your page was still rendering and there was a delay before you clicked on the button. This was enough time for the emailvar to get properly set. Then when you click the button, you just use the variables that are ‘global’ to the whole module.

Great to hear it works. As I’ve said, before, there are a 100 ways to code a solution. Just be careful about the promise being set by the user.getEmail call. I suspect that there is sufficient time delay once the form loads for the call to complete, so you got away without needing to use the async/await stuff. I don’t suspect that it is very time consuming to get the email of the current logged in user (probably a variable in the session). If you tried to retrieve info from a collection, it would probably have failed, since that process takes a lot longer to complete.

Yes, thanks to your help I got things moving along nicely. :slight_smile: Already got a page with database showing stuff just for one member. Hopefully I’m doing things right. :wink:

import wixData from 'wix-data';
import wixUsers from 'wix-users';
let userEmail = "none";
//
 $w.onReady(async function () {
    let user = wixUsers.currentUser; 
    let email = await user.getEmail().then((email) => { userEmail = email; });
    //
    $w("#dataset1").setFilter( wixData.filter().contains("email", userEmail)).then(() => 
    {
        $w("#button1").label = userEmail;
    }); 
});