Page 1 of 1
Straight away to an edit form after login
Posted: Mon Mar 05, 2018 11:46 am
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
Re: Straight away to an edit form after login
Posted: Mon Mar 05, 2018 1:44 pm
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 ?
Re: Straight away to an edit form after login
Posted: Mon Mar 05, 2018 5:06 pm
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
Re: Straight away to an edit form after login
Posted: Mon Mar 05, 2018 5:14 pm
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.
.
Re: Straight away to an edit form after login
Posted: Tue Mar 06, 2018 12:35 am
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
Re: Straight away to an edit form after login
Posted: Tue Mar 06, 2018 9:48 am
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
Re: Straight away to an edit form after login
Posted: Wed Mar 07, 2018 1:45 am
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
Re: Straight away to an edit form after login
Posted: Wed Mar 07, 2018 4:54 pm
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
Re: Straight away to an edit form after login
Posted: Wed Mar 07, 2018 6:27 pm
by admin
OK.