cafetito Posted December 29, 2011 Share Posted December 29, 2011 Hi, I'm trying to create the "MyModule" from the guide in http://forge.prestas...estaShop+module I have the main php + tpl file set up, it shows on the page, etc. Now I'm trying to set up the backend using the exact same code that's provided in the manual: <?php class Test extends ObjectModel { /** @var string Name */ public $test; protected $fieldsRequired = array( 'test' ); protected $fieldsSize = array( 'test' => 64 ); protected $fieldsValidate = array( 'test' => 'isGenericName' ); protected $table = 'test'; protected $identifier = 'id_test'; public function getFields() { parent::validateFields(); $fields[ 'test' ] = pSQL( $this->test ); return $fields; } } ?> and AdminTest.php: <?php include_once( PS_ADMIN_DIR . '/../classes/AdminTab.php' ); class AdminTest extends AdminTab { public function __construct() { $this->table = 'test'; $this->className = 'Test'; $this->lang = false; $this->edit = true; $this->delete = true; $this->fieldsDisplay = array( 'id_test' => array( 'title' => $this->l( 'ID' ), 'align' => 'center', 'width' => 25 ), 'test' => array( 'title' => $this->l( 'Name' ), 'width' => 200 ) ); $this->identifier = 'id_test'; parent::__construct(); } public function displayForm() { global $currentIndex; $defaultLanguage = intval( Configuration::get( 'PS_LANG_DEFAULT' ) ); $languages = Language::getLanguages(); $obj = $this->loadObject( true ); echo ' <script type="text/javascript"> id_language = Number('.$defaultLanguage.'); </script>'; echo ' <form action="' . $currentIndex . '&submitAdd' . $this->table . '=1&token=' . $this->token . '" method="post" class="width3"> ' . ($obj->id ? '<input type="hidden" name="id_' . $this->table . '" value="' . $obj->id . '" />' : '').' <fieldset><legend><img src="../img/admin/profiles.png" />' . $this->l( 'Profiles' ) . '</legend> <label>'.$this->l( 'Name:' ).' </label> <div class="margin-form">'; foreach ( $languages as $language ) echo ' <div id="name_' . $language['id_lang'|'id_lang'] . '" style="display: ' . ($language['id_lang'|'id_lang'] == $defaultLanguage ? 'block' : 'none') . '; float: left;"> <input size="33" type="text" name="name_' . $language['id_lang'|'id_lang'] . '" value="' . htmlentities( $this->getFieldValue( $obj, 'name', intval( $language['id_lang'|'id_lang'] ) ), ENT_COMPAT, 'UTF-8' ) . '" /><sup>*</sup> </div>'; $this->displayFlags( $languages, $defaultLanguage, 'name', 'name' ); echo ' <div class="clear"></div> </div> <div class="margin-form"> <input type="submit" value="' . $this->l( ' Save ' ) . '" name="submitAdd' . $this->table . '" class="button" /> </div> <div class="small"><sup>*</sup> ' . $this->l( 'Required field' ) . '</div> </fieldset> </form> '; } } ?> When I create the tab and try to add a new entry, the message " the field test is required" appears. After having a closer look at the code, I believe the parts I highlighted above should say "test" instead of "name" - but I'm not sure, as even modifying those parts doesn't bring up correct results.Could anybody be as kind as lending me a hand to get this going?Thanks in advance! Link to comment Share on other sites More sharing options...
da22 Posted February 8, 2012 Share Posted February 8, 2012 I have the same problem Link to comment Share on other sites More sharing options...
crazyfoolmurdock Posted March 28, 2012 Share Posted March 28, 2012 Hi Guys, I was having the exact same problem and found if you get rid of that $language stuff and replace the "name" with "test" it seems to work. My function looks like this: public function displayForm() { global $currentIndex; $defaultLanguage = intval(Configuration::get('PS_LANG_DEFAULT')); $languages = Language::getLanguages(); $obj = $this->loadObject(true); echo ' <script type="text/javascript"> id_language = Number('.$defaultLanguage.'); </script>'; echo ' <form action="' . $currentIndex . '&submitAdd' . $this->table . '=1&token=' . $this->token . '" method="post" class="width3"> ' . ($obj->id ? '<input type="hidden" name="id_' . $this->table . '" value="' . $obj->id . '" />' : '').' <fieldset><legend><img src="../img/admin/profiles.png" />' . $this->l('Profiles') . '</legend> <label>'.$this->l('Name:').' </label> <div class="margin-form">'; echo ' <div id="name_" style="display: block; float: left;"> <input size="33" type="text" name="test" value="' . htmlentities( $this->getFieldValue( $obj, 'test' ), ENT_COMPAT, 'UTF-8' ) . '" /><sup>*</sup> </div>'; echo ' <div class="clear"></div> </div> <div class="margin-form"> <input type="submit" value="'.$this->l('Save').'" name="submitAdd'.$this->table.'" class="button" /> </div> <div class="small"><sup>*</sup> '.$this->l('Required field').'</div> </fieldset> </form> '; } I know this is probably not the correct way of doing it, but at least it works! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now