问题
I need to add custom filed textbox(skill) in add vacancy section in orangehrm.
I am trying following code.It show text filed in the form but not add in the database.
orangehrm-3.1\symfony\plugins\orangehrmRecruitmentPlugin\modules\recruitment\templates\addJobVacancySuccess.php
Code:-
<?php
use_stylesheet(plugin_web_path('orangehrmRecruitmentPlugin', 'css/addJobVacancySuccess'));
use_javascript(plugin_web_path('orangehrmRecruitmentPlugin', 'js/addJobVacancySuccess'));
?>
<div class="box" id="addJobVacancy">
<div class="head">
<h1><?php echo isset($vacancyId) ? __('Edit Job Vacancy') : __('Add Job Vacancy'); ?></h1>
</div>
<div class="inner">
<?php include_partial('global/flash_messages'); ?>
<form name="frmAddJobVacancy" id="frmAddJobVacancy" method="post">
<?php echo $form['_csrf_token']; ?>
<?php echo $form["hiringManagerId"]->render();
?>
<fieldset>
<ol>
<li>
<?php echo $form['jobTitle']->renderLabel(__('Job Title') . ' <em>*</em>'); ?>
<?php echo $form['jobTitle']->render(array("maxlength" => 50)); ?>
</li>
<li>
<?php echo $form['name']->renderLabel(__('Vacancy Name') . ' <em>*</em>'); ?>
<?php echo $form['name']->render(array("maxlength" => 50)); ?>
</li>
<li>
<?php echo $form['hiringManager']->renderLabel(__('Hiring Manager') . ' <em>*</em>'); ?>
<?php echo $form['hiringManager']->render(array("maxlength" => 100)); ?>
</li>
<li>
<?php echo $form['noOfPositions']->renderLabel(__('Number of Positions')); ?>
<?php echo $form['noOfPositions']->render(array("maxlength" => 2)); ?>
</li>
<li class="largeTextBox">
<?php echo $form['description']->renderLabel(__('Description')); ?>
<?php echo $form['description']->render(array("cols" => 30, "rows" => 9)); ?>
</li>
<li>
<?php echo $form['skill']->renderLabel(__('Vacancy Skills') . ' <em>*</em>'); ?>
<?php echo $form['skill']->render(array("maxlength" => 50)); ?>
</li>
<li>
<?php echo $form['status']->renderLabel(__('Active')); ?>
<?php echo $form['status']->render(); ?>
</li>
<li class="labelRight">
<?php echo $form['publishedInFeed']->render(); ?>
<?php echo $form['publishedInFeed']->renderLabel(__('Publish in RSS feed(1) and web page(2)')); ?>
</li>
<?php include_component('core', 'ohrmPluginPannel', array('location' => 'add_layout_before_navigation_bar_1')) ?>
<li class="required">
<em>*</em> <?php echo __(CommonMessages::REQUIRED_FIELD); ?>
</li>
<li class="helpText">
1 : <?php echo __('RSS Feed URL') ?> : <?php echo link_to(null, 'recruitmentApply/jobs.rss', array('absolute' => true, 'target' => '_new')); ?>
</li>
<li class="helpText">
2 : <?php echo __('Web Page URL') ?> : <?php echo link_to(null, 'recruitmentApply/jobs.html', array('absolute' => true, 'target' => '_new')); ?>
</li>
</ol>
<p>
<?php if (isset($vacancyId)) { ?>
<input type="button" class="savebutton" name="btnSave" id="btnSave" value="<?php echo __("Edit"); ?>"/>
<input type="button" class="backbutton" name="btnBack" id="btnBack" value="<?php echo __("Back"); ?>"/>
<?php } else { ?>
<input type="button" class="savebutton" name="btnSave" id="btnSave"value="<?php echo __("Save"); ?>"/>
<?php } ?>
</p>
</fieldset>
</form>
</div>
<?php
if (isset($vacancyId)) {
echo include_component('recruitment', 'attachments', array('id' => $vacancyId, 'screen' => JobVacancy::TYPE));
}
?>
</div>
<script type="text/javascript">
//<![CDATA[
var hiringManagers = <?php echo str_replace(''', "'", $form->getHiringManagerListAsJson()) ?> ;
var hiringManagersArray = eval(hiringManagers);
var lang_typeForHints = '<?php echo __("Type for hints") . "..."; ?>';
var lang_negativeAmount = "<?php echo __("Should be a positive number"); ?>";
var lang_tooLargeAmount = "<?php echo __("Should be less than %amount%", array("%amount%" => '99')); ?>";
var lang_jobTitleRequired = '<?php echo __(ValidationMessages::REQUIRED); ?>';
var lang_vacancyNameRequired = '<?php echo __(ValidationMessages::REQUIRED); ?>';
var lang_enterAValidEmployeeName = "<?php echo __(ValidationMessages::INVALID); ?>";
var lang_nameExistmsg = "<?php echo __("Already exists"); ?>";
var vacancyNames = <?php echo $form->getVacancyList(); ?>;
var vacancyNameList = eval(vacancyNames);
var lang_edit = "<?php echo __("Edit"); ?>";
var lang_save = "<?php echo __("Save"); ?>";
var lang_cancel = "<?php echo __("Cancel"); ?>";
var lang_back = "<?php echo __("Back"); ?>";
var linkForAddJobVacancy = "<?php echo url_for('recruitment/addJobVacancy'); ?>";
var lang_descriptionLength = "<?php echo __(ValidationMessages::TEXT_LENGTH_EXCEEDS, array('%amount%' => 40000)) ?>";
var backBtnUrl = '<?php echo url_for('recruitment/viewJobVacancy?'); ?>';
var backCancelUrl = '<?php echo url_for('recruitment/addJobVacancy?'); ?>';
<?php if (isset($vacancyId)) { ?>
var vacancyId = '<?php echo $vacancyId; ?>';
<?php } else { ?>
var vacancyId = "";
<?php } ?>
//]]>
</script>
回答1:
Try this..
1)You need to create filed name (skill) in your table.
2)Add following lines to orangehrm-3.1\symfony\lib\model\doctrine\orangehrmRecruitmentPlugin\base\BaseJobVacancy.class.php
Inside public function setTableDefinition(){}
$this->hasColumn('skill', 'string', 100, array(
'type' => 'string',
'length' => 100,
));
3)Add following lines to orangehrm-3.1\symfony\plugins\orangehrmRecruitmentPlugin\modules\recruitment\templates\addJobVacancySuccess.php
Inside the form following lines
<li>
<?php echo $form['skill']->renderLabel(__('Vacancy Skills') . ' <em>*</em>'); ?>
<?php echo $form['skill']->render(array("maxlength" => 50)); ?>
</li>
4)Add following lines to orangehrm-3.1\symfony\plugins\orangehrmRecruitmentPlugin\lib\form\AddJobVacancyForm.php
Inside Widgetarray like following code
$this->setWidgets(array(
'jobTitle' => new sfWidgetFormSelect(array('choices' => $jobTitleList)),
'name' => new sfWidgetFormInputText(),
'hiringManager' => new sfWidgetFormInputText(),
......
.....
'skill' => new sfWidgetFormInputText(),
));
Inside setValidatorsarray like following code
$this->setValidators(array(
'jobTitle' => new sfValidatorString(array('required' => true)),
'name' => new sfValidatorString(array('required' => true)),
'hiringManager' => new sfValidatorString(array('required' => true)),
.....
.....
....
'skill' => new sfValidatorString(array('required' => true)),
));
Inside following code in if loop "if (isset($vacancy) && $vacancy != null) {}"
$this->setDefault('skill', $vacancy->getSkill());
Inside save() function add following following code
$jobVacancy->skill = $this->getValue('skill');
回答2:
I am agree with Deena's answer. I created a new field in Salary section just like that.
Checkout following link
http://forum.orangehrm.com/viewtopic.php?f=6&t=18413&sid=fa8d38e5b5825097a6299ef534636c93
来源:https://stackoverflow.com/questions/27780354/how-to-add-custom-input-field-in-orangehrm-add-vacancy-section