public function actionIndex(){
$options = XenForo_Application::get('options');
$visitor = XenForo_Visitor::getInstance();
if (checkboxIsTicked) {
// Do Stuff
}
$_POST['checkBox'];
ThanksPHP:$checkBox = $this->_input->filterSingle('name_checkbox', XenForo_Input::BOOLEAN);
if ($checkBox)
$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();
}
In a template I have insert this :WHere your html of checkbox? WHy not work?
<input type="checkbox" name="userBox">
$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();
}
<input type="checkbox" name="checkBox" value="1" />
I don't see the error :/Look at on your code
if ($this->_input->filterSingle('nameOfCheckbox', XenForo_Input::BOOLEAN);)
{
// do something
}
else
{
// do something else
}
I'll pm you with the entire codeI'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 }
We use essential cookies to make this site work, and optional cookies to enhance your experience.