Advertisement:

Author Topic: [SOLVED] How to store value in session for form field extended from From class?  (Read 346 times)

Syed

  • Full Member
  • ***
  • Posts: 240
I am working on a plugin and want to get data from field s_phone_mobile on item-post.php for unregistered user and it works fine.

The only issue i am facing, it do not store value of text field named s_phone_mobile to Session.

Here is my code

Code: [Select]
<?php
    
class MyNewForm extends Form {

        static public function 
my_mobile_number_text($item null) {
            if(
$item==null) { $item osc_item(); };
            if( 
Session::newInstance()->_getForm('s_phone_mobile') != "" ) {
                
$item['s_phone_mobile'] = Session::newInstance()->_getForm('s_phone_mobile');
            }
            
parent::generic_input_text('s_phone_mobile', (isset($item['s_phone_mobile'])) ? $item['s_phone_mobile'] : null);
            return 
true;
        }
        
    }
?>
« Last Edit: April 17, 2018, 06:28:17 am by Syed »

Syed

  • Full Member
  • ***
  • Posts: 240

Someone please guide me to the right direction.

Regards,

calinbehtuk

  • Sr. Member
  • ****
  • Posts: 389
You can check car thelephone plugin, it free and you will see how the value is stored in session.

Code: [Select]
Session::newInstance()->_setForm('telephone', Params::getParam("telephone"));
Session::newInstance()->_keepForm('telephone');

The plugin use some hooks that run before item is publish to store this value in session in case of error.
See index.php from plugin

Code: [Select]
osc_add_hook('pre_item_post', 'pre_post_store_value');


patrickFromCroatia

  • Sr. Member
  • ****
  • Posts: 474
Hello,

As you can see in @calinbehtuk 's code, you need to user "setForm" and "keepForm" when storing fields in session.

Regards.

Syed

  • Full Member
  • ***
  • Posts: 240
Thank you calinbehtuk,


Please look at my another issue and share your knowledge.
https://forums.osclass.org/general-help/how-to-prevent-mobile-number-update-on-update-profile-page/


Regards