Updating knop_user data after manual database update

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Updating knop_user data after manual database update

Jason Pettis-2
Hello, it's another knop-newbie question!

Following in the steps of my previous question, how do I update data in the knop_user variable if I update values in the users' database record?

I have a manual-created form (not made with knop_form) that I'm using to update a user's record in the database

I am updating the record manually using an inline (not using knop_database functions). After the update, I want to refresh the data in the knop_user variable. 

I initially created my user var with knop functions:
var('s_user' = knop_user(-userdb=$d, -userfield='email', -passwordfield='password'), 's_lang'=null);

and then authenticate the user with values submitted through a knop_form element called $loginform:
$s_user -> login(-username=($loginform -> username), -password=($loginform -> password));

Later on, the user updates data using my not-knop_form and an inline using SQL.

Inline( -database='mydb', -sql='exec sql...');
/inline;

What knop_user functions do I use to refresh all fields on the user record in the user var?

Thanks!
-Jason Pettis
Reply | Threaded
Open this post in threaded view
|

Re: Updating knop_user data after manual database update

stevepiercy
On 6/15/12 at 11:47 AM, [hidden email] (Jason Pettis) pronounced:

>Hello, it's another knop-newbie question!
>
>Following in the steps of my previous question, how do I update data in the
>knop_user variable if I update values in the users' database record?
>
>I have a manual-created form (not made with knop_form) that I'm using to
>update a user's record in the database
>
>I am updating the record manually using an inline (not using knop_database
>functions). After the update, I want to refresh the data in the knop_user
>variable.
>
>I initially created my user var with knop functions:
>var('s_user' = knop_user(-userdb=$d, -userfield='email',
>-passwordfield='password'), 's_lang'=null);
>
>and then authenticate the user with values submitted through a knop_form
>element called $loginform:
>$s_user -> login(-username=($loginform -> username), -password=($loginform
>-> password));
>
>Later on, the user updates data using my not-knop_form and an inline using
>SQL.
>
>Inline( -database='mydb', -sql='exec sql...');
>/inline;
>
>What knop_user functions do I use to refresh all fields on the user
>record in the user var?

Do this at the same time you update the record.

     Inline( -database='mydb', -sql='exec sql...');
     /inline;

     // update the user session vars
     // pseudo-code.  You can loop through $form->keys or grab
just one field at a time, for example.
     $s_user->setdata(somekey = somevalue);

     // usually this is in your session handler, often in cfg__global.inc
     session_start(-name=$auth_cookie_name,-expires=$user_session);
     session_addvar(-name=$auth_cookie_name, 's_user');

Further, however, due to the nature of sessions and how their
variable values are set only after the completed execution of
the current page, you would need to do a redirect or load
another page to get access to those session values.

After you load a new page, then you would access the user
session vars and load them into form fields using the library
file and knop_form->setvalue.

     // place the following in the proper logic block in library file
     $f->loadfields(-params=$initfields);
     $f->setvalue('somefield'=$s_user->getdata('somekey'));

Oh, but, wait!  You're doing it the hard way without knop_form!  ;)

That's OK, you can still just use:

     <input type="text" name="myfield" value="[$s_user->getdata('somekey')]">

--steve

>Thanks!
>-Jason Pettis
>

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Steve Piercy               Web Site Builder              
Soquel, CA
<[hidden email]>                  <http://www.StevePiercy.com/>


--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://lasso.2283332.n4.nabble.com/Knop-Framework-Discussion-f3157831.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: Updating knop_user data after manual database update

Johan Solve-2
At 14.58 -0700 2012-06-15, Steve Piercy - Web Site Builder wrote:
>>What knop_user functions do I use to refresh all fields on the user
>>record in the user var?

Good question...

>Further, however, due to the nature of sessions and how their variable values are set only after the completed execution of the current page, you would need to do a redirect or load another page to get access to those session values.

No, session variables are also page variables so they are available on the same page. Do you mix it up with cookies?


--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:[hidden email]
 (spam-safe email address, replace '-' with 'a')

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://lasso.2283332.n4.nabble.com/Knop-Framework-Discussion-f3157831.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
Reply | Threaded
Open this post in threaded view
|

Re: Updating knop_user data after manual database update

stevepiercy
On 6/16/12 at 11:07 PM, [hidden email] (Johan Solve) pronounced:

>At 14.58 -0700 2012-06-15, Steve Piercy - Web Site Builder wrote:
>>>What knop_user functions do I use to refresh all fields on the user
>>>record in the user var?
>
>Good question...
>
>>Further, however, due to the nature of sessions and how their variable values are set
>only after the completed execution of the current page, you
>would need to do a redirect or load another page to get access
>to those session values.
>
>No, session variables are also page variables so they are
>available on the same page. Do you mix it up with cookies?

Yes, sorry.  I don't know what I was thinking in that sentence.  
Maybe something about needing to use session_start to retrieve
session vars on a subsequent page load.

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- --
Steve Piercy               Web Site Builder              
Soquel, CA
<[hidden email]>                  <http://www.StevePiercy.com/>


--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
List archive http://lasso.2283332.n4.nabble.com/Knop-Framework-Discussion-f3157831.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/