Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Straight away to an edit form after login

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Locked
Audioko
Posts: 14
Joined: Tue Feb 06, 2018 10:20 am
Location: Amsterdam, The Netherlands

Straight away to an edit form after login

Unread post by Audioko »

Hi,

I have a browse-edit form with customers that are all users. That means that they have all an user_id.
Each customer is supposed to login , then select his own record and fill in adress, date of birth etc, etc...
I created a field in the customer table: cus_user_id and added this as column (width 0 px) on the customer form.

What I want to realise is that a customer after logging in goes right away to his own edit form.
I suppose this has to be done with the JS function
nuForm('form_id', ?, '', '', 1)
where ? is the cus_user_id]

My question is how to get the string of the customer_id (wich can be queried) in this function?
Or, put it like this, how to pick-up a php variable in JS

A hint or an en example code would be helpful

thanks,
Ko
Last edited by Audioko on Mon Mar 05, 2018 3:00 pm, edited 1 time in total.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Straight away to an edit form after login

Unread post by toms »

Ko,

This is my idea (but not quite working because of a little issue...)

1. Clone the form nuuserhome. Name it like customersuserhome (Code) and give it a description (like Customers Home)
2. Add this PHP code to the BE event: nuRunPHPHidden('openFormForCustomer', 1);
3. Assign the customersuserhome to your customers (Home ► Access Levels)

4. Create a procedure: Home ► Build Procedure ► Add
runPHP.png

Code: Select all

function getRecordIdforCustomer() {
    $sql = "SELECT customers_test_id FROM customers_test WHERE cus_user_id = '#USER_ID#'";
    $qry = nuRunQuery($sql);
    $row = db_fetch_row($qry);
    return $row[0];
}

$r = getRecordIdforCustomer();

$js = " console.log('nuForm'); nuForm('5a9918cdda1cc39', '$r' ,'', '',0); ";

nuJavascriptCallback($js);
5. Now when a customer logs in, the nuRunPHPHidden() is executed and runs the code 'openFormForCustomer'

The only problem..

console.log() doesn't output anything and consequently, the form is not opened.. It looks like nuJavascriptCallback() is not executed.

I'm a little clueless right now. Maybe Steven or someone else can help out ?
You do not have the required permissions to view the files attached to this post.
Audioko
Posts: 14
Joined: Tue Feb 06, 2018 10:20 am
Location: Amsterdam, The Netherlands

Re: Straight away to an edit form after login

Unread post by Audioko »

toms,

thanks.

I made a simple test.php file with the query outside nubuilder
query.jpg
and got the correct output
output.jpg
This is the same as what nuRunQuery() in your script does I suppose?
And if so, how can I get the output on the console in element inspector?

I know this is not quite nuBuilder stuff but if you can give me a hint then I am one step further.

thanks a lot,
Ko
You do not have the required permissions to view the files attached to this post.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Straight away to an edit form after login

Unread post by toms »

Ko,

Yes, this is what my function returns too: The record id. You can use nuDebug() to output e.g. a string.
It can be viewed by clicking nuDebug Results in the Options menu.

.
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Straight away to an edit form after login

Unread post by admin »

Ko,

You can try this - (Your customers will need to log in and click a Button on whatever their Home Page is, to open the Form).

Create the Form

Filter Browse by User ID
sql.PNG
Add User ID when adding a new record.
javascript.PNG

Code: Select all

if(nuIsNewRecord()){

    $('#cus_user_id')
    .val(nuCurrentProperties().user_id)
    .change()
    
    nuHasNotBeenEdited();
    
}
browse.PNG
edit.PNG

Obviously, you would hide the cus_user_id field.

Hope this helps.

Steven
You do not have the required permissions to view the files attached to this post.
Audioko
Posts: 14
Joined: Tue Feb 06, 2018 10:20 am
Location: Amsterdam, The Netherlands

Re: Straight away to an edit form after login

Unread post by Audioko »

Steven,

It helps me to update the cus_user_id from the customer table.
I used an update script in php.
This is much easier.
Thanks.

What I actually wanted is this:
cus_login.jpg
So, after clicking on the login button the custumer would be on the edit page of his own record without having to click on his own row.
And that's where I thought I would use nuForm('form_id', 'customer_id', '', '', 1).
Is this assumption correct?

Of course, it's not a big deal, but I am curious to find out how to realise this with Javascript.

Ko
You do not have the required permissions to view the files attached to this post.
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Straight away to an edit form after login

Unread post by admin »

Ko,

Here is another idea...
edit_inside_homepage.png
This should work as long as the Primary Key of the Form is the user_id.


Steven
You do not have the required permissions to view the files attached to this post.
Audioko
Posts: 14
Joined: Tue Feb 06, 2018 10:20 am
Location: Amsterdam, The Netherlands

Re: Straight away to an edit form after login

Unread post by Audioko »

Steven,


A. Logging in with button and row on browse form shows 'Evelien'
B. Logging in with iFrame gives in my case an empty record.
docs.jpg
The element inspector gives
keys.jpg
And yes, user_id Evelien == customer_id Evelien : 5a99060cb2aa0c4

Unless you know immediately whats going wrong, let's close the topic.
It's not that important
I appreciate your hints.

Ko
You do not have the required permissions to view the files attached to this post.
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Straight away to an edit form after login

Unread post by admin »

OK.
Locked