Conditionn Checkbox

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
 
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'];
?
 
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'] > 0 ? $visitor['username'] : new XenForo_Phrase('guest'));
               $dw->save();
            }
 
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 :/
 
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'] > 0 ? $visitor['username'] : new XenForo_Phrase('guest'));
               $dw->save();
            }

My template :
HTML:
<input type="checkbox" name="checkBox" value="1" />
 
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
}
 
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
}
I'll pm you with the entire code :p
 
Back
Top Bottom