1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Input from option to database

Discussion in 'XenForo Development Discussions' started by kalco, Nov 19, 2015.

  1. kalco

    kalco Active Member

    Hi to all,
    I developing one add-on and i have one question.

    So if possibility to insert data to database from option?

    i have two option:

    1. one text field
    2. radio button with two option
    (Same from inage above)

    My database table is:

    CREATE TABLE IF NOT EXISTS `xf_addon1` (
      `news_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `name` varchar(128) NOT NULL,
      `show_description` tinyint(3) unsigned NOT NULL,
      PRIMARY KEY (`news_id`)
    Can i make insert input from field direct to 'name' and from radio button direct to 'show_description' ?

    Thank you
  2. Robust

    Robust Well-Known Member

    You can get the XF options using XenForo_Application::getOptions()
    Use magic accessors (if you like to call that, they have a real name) to access the options field. e.g. $options->theOptionID
    Then run a db query as normal to put it in.
  3. kalco

    kalco Active Member

    I know that, but i can't write in db table from option fields...
  4. Jeremy P

    Jeremy P Well-Known Member

    Why not? You'd just grab the values like @Robust describes and use a regular insert/update query to write to the database table.
  5. Robust

    Robust Well-Known Member

    Prepared statements or $db->quote, either would do...

Share This Page