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

Conditionn Checkbox

Discussion in 'XenForo Development Discussions' started by Walky, Oct 11, 2014.

  1. Walky

    Walky Member

    Hello !
    I would like to create a condition with a checkbox :)
    I have added this in a template :
    HTML:
    <input type="checkbox" name="checkBox">
    And I would like to do a condition if the checkbox is checked :)
    Do i need to add PHP file via FTP or not necessary ?

    Thanks
     
  2. Walky

    Walky Member

    EDIT :

    I have added the checkbox in the template : test_Template
    And I would like to get the value of the checkbox (ticked or not) in a PHP file How can I do this ?

    Example :
    PHP:
    public function actionIndex(){
            
    $options XenForo_Application::get('options');
            
    $visitor XenForo_Visitor::getInstance();
           
             if (
    checkboxIsTicked) {
                    
    // Do Stuff
             
    }
    Maybe I need to use this :
    PHP:
    $_POST['checkBox'];
    ?
     
  3. Nobita.Kun

    Nobita.Kun Well-Known Member

    PHP:
    $checkBox $this->_input->filterSingle('name_checkbox'XenForo_Input::BOOLEAN);
     
    Walky likes this.
  4. Walky

    Walky Member

    Thanks :D
    So the condition will be :
    PHP:
    if ($checkBox)
    ?
     
    Last edited: Oct 12, 2014
  5. Nobita.Kun

    Nobita.Kun Well-Known Member

  6. Walky

    Walky Member

    Still doesn't work :(

    PHP:
    $checkBox $this->_input->filterSingle('userBox'XenForo_Input::BOOLEAN);
               
                if (
    $checkBox)
                {           
                   
    $messageId XenForo_Application::get('options')->messageId;
               
                   
    $dw XenForo_DataWriter::create('Test_DataWriter_Test');
                   
    $dw->set('user_id'2);
                   
    $dw->set('username''hakdi');
                   
    $dw->save();
                }
                else
                {
                    
    $dw XenForo_DataWriter::create('Test_DataWriter_Test');
                   
    $dw->set('user_id'$visitor['user_id']);
                   
    $dw->set('username'$visitor['user_id'] > $visitor['username'] : new XenForo_Phrase('guest'));
                   
    $dw->save();
                }           
     
  7. Nobita.Kun

    Nobita.Kun Well-Known Member

    WHere your html of checkbox? WHy not work?
     
  8. Walky

    Walky Member

    In a template I have insert this :
    HTML:
    <input type="checkbox" name="userBox">
    
     
  9. Nobita.Kun

    Nobita.Kun Well-Known Member

    Should be:
    Code:
    <input type="checkbox" name="checkBox" value="1" />
     
  10. Walky

    Walky Member

    Not work too :(

    I tried to edit this :
    PHP:
    if ($checkBox)
    By :

    PHP:
    if (isset($checkBox))
    The results change but when I tick the result still the same :/
     
  11. Nobita.Kun

    Nobita.Kun Well-Known Member

    You should read again about my suggestion.
     
  12. Walky

    Walky Member

    Yes but still not mork :/

    PHP Code :
    PHP:
    $checkBox $this->_input->filterSingle('checkBox'XenForo_Input::BOOLEAN);
               
                if (
    $checkBox)
                {           
                   
    $messageId XenForo_Application::get('options')->messageId;
               
                   
    $dw XenForo_DataWriter::create('Test_DataWriter_Test');
                   
    $dw->set('user_id'2);
                   
    $dw->set('username''flo');
                   
    $dw->save();
                }
                else
                {
                    
    $dw XenForo_DataWriter::create('Test_DataWriter_Test');
                   
    $dw->set('user_id'$visitor['user_id']);
                   
    $dw->set('username'$visitor['user_id'] > $visitor['username'] : new XenForo_Phrase('guest'));
                   
    $dw->save();
                }       
    My template :
    HTML:
    <input type="checkbox" name="checkBox" value="1" />
    
     
  13. Nobita.Kun

    Nobita.Kun Well-Known Member

    Look at on your code :)
     
  14. Walky

    Walky Member

    I don't see the error :/
     
  15. Walky

    Walky Member

  16. Lawrence

    Lawrence Well-Known Member

    I'll assume your form action is set to point to where your check box value will be read.
    If it is set correctly, then the post made by @Nobita.Kun will work. As it doesn't work you will need to post more of your code (template, and the method) for us to help :)

    PHP:
    if ($this->_input->filterSingle('nameOfCheckbox'XenForo_Input::BOOLEAN);)
    {
           
    // do something
    }
    else
    {
         
    // do something else
    }
     
  17. Walky

    Walky Member

    I'll pm you with the entire code :p
     
  18. Walky

    Walky Member

    Didn't still find the solution :(
    The code comes from a file of the TaigaChat Pro add-on (@Luke Foreman) ;)
    I can PM you with the entire code
     

Share This Page