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

How do I add an input field in the Admin CP and create table

AndyB

Well-known member
#1
I'm creating an add-on and I would like to allow the admin to set the number of smilies allowed per post.

I assume the steps to do this are:

1) Create link in the Tools tab (Template Modification) which template?
2) Create form for the input. Create a template.
3) Add code to create a table in the database to store the value
4) Add code read the value in the table created
5) Modify error phrase so it indicates the maximum smilies allowed
6) Create uninstall code to remove table
 

AndyB

Well-known member
#7
library/Andy/SmilieCount/Route/Prefix/SmilieCount.php

I have no idea if the code below is correct.

PHP:
<?php

class Andy_SmilieCount_Route_Prefix_SmilieCount implements XenForo_Route_Interface
{
   public function match($routePath, Zend_Controller_Request_Http $request, XenForo_Router $router)
   {
     return $router->getRouteMatch('Andy_SmilieCount_ControllerAdmin_Tools', $routePath);
   }
}

?>
 
Last edited:

AndyB

Well-known member
#8
At this point when I click the Smilie Count link under the Tools tab it properly calls the below file. What is the correct responseRedirect code. What I have there now doesn't show the pretty jquery dropdown.

library/Andy/ControllerAdmin/Tools.php

PHP:
<?php

class Andy_SmilieCount_ControllerAdmin_Tools extends XenForo_ControllerAdmin_Tools
{
	public function actionIndex()
	{		
		return $this->responseRedirect(
			XenForo_ControllerResponse_Redirect::SUCCESS,
			XenForo_Link::buildAdminLink('tools')
		);	
	}
}

?>
 
Last edited:

AndyB

Well-known member
#9
How should I edit the code below so that it brings up the andy_smiliecount template?

PHP:
<?php

class Andy_SmilieCount_ControllerAdmin_Tools extends XenForo_ControllerAdmin_Tools
{
    public function actionSmiliecount()
    {
    
        $post = 'test';
        // display andy_smiliecount template
        $viewParams = array('post' => $post);
        return $this->responseView('Andy_ViewPublic_Post','andy_smiliecount',$viewParams);
    }
    
    public function actionSmiliecountsave()
    {        
        
        return $this->responseRedirect(
            XenForo_ControllerResponse_Redirect::SUCCESS,
            XenForo_Link::buildAdminLink('tools')
        );
    }
}

?>
 
Last edited:

AndyB

Well-known member
#12
My andy_smiliecount template

Code:
<xen:title>Smilie Count</xen:title>

<form action="{xen:link 'smiliecount/smiliecount-save', $post}" method="post" class="xenForm AutoValidator" data-redirect="on">

<fieldset>

<dl class="ctrlUnit">
  <dt><label>Enter maximum smilie count per post:</label></dt>
  <dd><input type="text" name="new_smilie_count" size="10" value="{$post.formatted_date}" class="textCtrl titleCtrl"></dd>
</dl>

<dl class="ctrlUnit submitUnit">
  <dt></dt>
  <dd><input type="submit" value="Submit" class="button primary" accesskey="s" /></dd>
</dl>
</fieldset>

<input type="hidden" name="_xfToken" value="{$visitor.csrf_token_page}" />
</form>
 

AndyB

Well-known member
#13
When I click the Submit button, I get the following:

The following error occurred:
Route smiliecount/smiliecount-save could not be found.
 

AndyB

Well-known member
#17
Tools.php

PHP:
<?php

class Andy_SmilieCount_ControllerAdmin_Tools extends XenForo_ControllerAdmin_Tools
{
   public function actionIndex()
   {
     
     $post = '5';
     // display andy_smiliecount template
     $viewParams = array('post' => $post);
     return $this->responseView('Andy_ViewPublic_Post','andy_smiliecount',$viewParams);
   }
     
   public function actionSave()
   {       
     // make sure data comes from $_POST
     $this->_assertPostOnly();
     
     // get new_post_date from overlay     
     $newSmilieCount = $this->_input->filterSingle('new_smilie_count', XenForo_Input::STRING);
     
     //########################################
     // save $newSmilieCount
     
     
     
     
     //########################################
     // response redirect        
       
     return $this->responseRedirect(
       XenForo_ControllerResponse_Redirect::SUCCESS,
       XenForo_Link::buildAdminLink('tools')
     );   
   }
}

?>
 

AndyB

Well-known member
#20
My current directory and files:

library
--Andy
----SmilieCount
------ControllerAdmin
--------Tools.php
------ControllerPublic
--------Forum
--------Post
--------Thread
------Listener.php
------Model
--------Smilie.php
------Route
--------Prefix
----------SmilieCount