I'm trying to create a new user but I'm having trouble trying to create the user because some of the values that are needed to create a user must be default values that I'm not quite sure how to set. I also need to input into a different table while the actual "create" happens from a different controller.
Here is my form code:
<?php
/* #var $this SystemUserController */
/* #var $model SystemUser */
/* #var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'system-user-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<!--
<div class="row">
<?php echo $form->labelEx($model,'party_id'); ?>
<?php echo $form->textField($model,'party_id',array('size'=>20,'maxlength'=>20)); ?>
<?php echo $form->error($model,'party_id'); ?>
</div>
!-->
<div class="row" id="toshow" style="display:none" name="suppliers"> <?php $supplier = SupplierHead::model()->findAll();
$list = CHtml::listData($supplier ,'head_id','head_name');
echo $form->DropDownList($model,'party_id',
$list, array('prompt'=>'Select Supplier')); ?>
</div>
<button id="abutton">Already a Supplier</button>
<script>
$(document).ready(function() {
$("#abutton").click(function(e){
e.preventDefault();
$("#toshow").css('display', 'block');
});
});
</script>
<div class="row">
<?php echo $form->labelEx($model,'username'); ?>
<?php echo $form->textField($model,'username',array('size'=>60,'maxlength'=>200)); ?>
<?php echo $form->error($model,'username'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'password'); ?>
<?php echo $form->passwordField($model,'password',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'password'); ?>
</div>
<script>
$("#supplier").click(function () {
$("#suppliers").show("slow");
});
</script>
<!--
<div class="row">
<?php echo $form->labelEx($model,'date_last_login'); ?>
<?php echo $form->textField($model,'date_last_login'); ?>
<?php echo $form->error($model,'date_last_login'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'status'); ?>
<?php echo $form->textField($model,'status',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($model,'status'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'date_created'); ?>
<?php echo $form->textField($model,'date_created'); ?>
<?php echo $form->error($model,'date_created'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'date_modified'); ?>
<?php echo $form->textField($model,'date_modified'); ?>
<?php echo $form->error($model,'date_modified'); ?>
</div>
--!>
<div class="row">
<?php echo $form->labelEx($model,'user_role'); ?>
<?php echo $form->textField($model,'user_role',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'user_role'); ?>
</div>
<!--
<div class="row">
<?php echo $form->labelEx($model,'isLogin'); ?>
<?php echo $form->textField($model,'isLogin'); ?>
<?php echo $form->error($model,'isLogin'); ?>
</div>
--!>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
As you can see, I've commented out the attributes that I don't want to use. I also fixed the SystemUser model attributes rules() to define which attributes won't be needed for user input here:
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('party_id, username, password', 'required'),
//array('isLogin', 'numerical', 'integerOnly'=>true),
array('party_id', 'length', 'max'=>20),
array('username', 'length', 'max'=>200),
array('password, user_role', 'length', 'max'=>255),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('party_id, username' 'on'=>'search'),
);
}
Finally, there's also a drop down list I included above from the form that is required to be inserted into a model of a different controller. How do I go about this?
The attributes that need default values are as follows:
date_last_login
status
date_created
date_modified
EDIT
I've uploaded a picture of what happens when I select "Create"
I decided not to add defaults try keeping them NULL just to see if the rules() would work. I
Any help?
Yii's model has methods such as:
beforeSave()
afterSave()
beforeValidate()
afterValidate()
and so on ...
which can be overridden into your model. If you want to set any default value before saving/validating you can use from mentioned methods in your model. Please take a look at the following example:
public function beforeSave() {
if (parent::beforeSave()) {
//Example
$this->date_modified=new New CDbExpression('NOW()');
//ANOTHER EXAMPLE
$this->date=date('Y-m-d',time());
// YOU CAN EVEN CALLING A WEBSERVICE
// ANYTHING THAT YOU WANT TO DO BEFORE SAVING INTO DATABASE
return true;
}
}
other methods such as afterSave and ... work like above.
I hope it help :)
You can use the rules for it like
public function rules()
{
return array(
// your other rules
array('myField','default','value'=>'my Name'),
// for date type use new CDbExpression('NOW()')
array('date_modified','default',
'value'=>new CDbExpression('NOW()'),
),
// rest of your rules
);
}
Try with this data type:
date_last_login : timestamp
status : enum('active','inactive')
date_created : timestamp
date_modified : timestamp
Defult Time stamp: current_timestamp
Related
I am developing this website that requires me to combine two models in one view where they have one to many relationship between them. The models name is Home and Image meaning Home has many Images but Image only has one Home.
I have manged to combine The view together but the problem that i encountering is to get all of the images. For example i have 6 images i want to display them or if i have 5 images i want to display them.
Home Controller UpdateMethod
public function actionUpdate($id)
{
$home=$this->loadModel($id);
$image=Image::model()->findByAttributes(array('homeId'=>$home->id));
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Home'],$_POST['Image'])){
$home->attributes=$_POST['Home'];
$image->attributes=$_POST['Image'];
$valid=$home->validate();
$valid=$image->validate() && $valid;
if($valid){
if($home->save()){
$image->save();
}
}
}
$this->render('update',array(
'home'=>$home,
'image'=>$image,
));
}
My _form.php to join them together
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'home-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($home); ?>
<div class="row">
<?php echo $form->labelEx($image,'imageUrl'); ?>
<?php echo $form->textField($image,'imageUrl',array('size'=>60,'maxlength'=>100)); ?>
<?php echo $form->error($image,'imageUrl'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($home,'recentEvents'); ?>
<?php echo $form->textField($home,'recentEvents',array('size'=>60,'maxlength'=>100)); ?>
<?php echo $form->error($home,'recentEvents'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($home,'introduction'); ?>
<?php echo $form->textArea($home,'introduction',array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($home,'introduction'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($home->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
Update I had FindByattribues instead of FindAllByAttribues in the model so now it is returning an array. Now how to process that array in the view?
Okay i figured it out by myself posting this to maybe help someone who needs it. I the view i did the following.
<?php
foreach($image as $image){
?>
<div class="row">
<?php echo $form->labelEx($image,'imageUrl'); ?>
<?php echo $form->textField($image,'imageUrl',array('size'=>60,'maxlength'=>100)); ?>
<?php echo $form->error($image,'imageUrl'); ?>
</div>
<?php
}
?>
I have two models
1)TblRegistration : $model as object
-director
-experience
-language
2)TblLogin : $model2 as object
-email
-password
Both fields are included in TblRegistration/_form.php
By defaut TblRegistration fields validation is included in rules().
views/tblRegistration/_form.php
<div class="row">
<?php echo $form->labelEx($model,'director'); ?>
<?php echo $form->textField($model,'director',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($model,'director'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'experience'); ?>
<?php echo $form->textField($model,'experience'); ?>
<?php echo $form->error($model,'experience'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'language'); ?>
<?php echo $form->textField($model,'language',array('size'=>50,'maxlength'=>50)); ?>
<?php echo $form->error($model,'language'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model1,'email'); ?>
<?php echo $form->textField($model1,'email'); ?>
<?php echo $form->error($model1,'email'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model1,'password'); ?>
<?php echo $form->textField($model1,'password'); ?>
<?php echo $form->error($model1,'password'); ?>
</div>
models/TblRegistration.php
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('director, experience, language', 'required'),
array('experience', 'numerical', 'integerOnly'=>true),
array('director, language', 'length', 'max'=>50),
// The following rule is used by search().
// #todo Please remove those attributes that should not be searched.
array('reg_id, director, experience, language', 'safe', 'on'=>'search'),
);
}
I want to include TblLogin fields into model/TblRegistraion rules for validation.
You can manually validate a model by calling the validate() method:
if($modelA->validate() && $modelB->validate()) {
// Call save method, fix foreign keys, etc
$this->redirect(array('view'));
}
If there is an error the page will not be redirected so your form will reload. $form->error() will highlight the error fields. Also, when the first argument of errorSummary is an array containing your models, it will summarize them all for you.
I have two different table and i want to insert data in both of them at a time.
ONE table is verse
verse(id, topic_id, surah_id, verse_text) // id is primary key,
Second table is verse_translations
verse_translations(id, verse_id, language_id, translations_text) // id is primary key, language_id is foreign key references with language table, // verse_id is foreign key references with verse table.
Verse Create File (_form.php)
<div class="form">
<?php $form = $this->beginWidget('CActiveForm', array('id'=>'verse-form', 'enableAjaxValidation'=>true)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<div class="row">
<?php echo $form->labelEx($model, 'verse_text'); ?>
<?php echo $form->textArea($model, 'verse_text', array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($model,'verse_text'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model, 'verse_translations'); ?>
<p class="<?php echo "tran".$model->id ?>">
<?php
$errors = array_filter($model->verseTranslations);
if(!empty($errors)) {
foreach($model->verseTranslations as $vt) {
echo $form->textArea($model, 'translation_text', array('value'=>$vt['translation_text'], 'rows'=>6, 'cols'=>50));
}
}
?>
</p>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
As you may see from _form file, I have called the data from verse_translations table.
Now my questions are:
How I keep the value of textArea that it will go in an array in controller? And How can I insert data in verse_translation table from verse create controller.
The output of _form file is like that.
Verse Create Controller Code.
public function actionCreate()
{
$model=new Verse;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Verse']))
{
$model->attributes=$_POST['Verse'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('create',array(
'model'=>$model,
));
}
Hope you understand it clearly.
Thanks
I think you should try this
public function actionCreate()
{
$verse_model=new Verse;
$verse_translation_model=new Verse_translations;
if(isset($_POST['Verse']) && isset($_POST['Verse_translations']))
{
$verse_model->attributes=$_POST['Verse'];
$verse_translation_model->attributes=$_POST['Verse_translations'];
$verse_model->save();
$verse_translation_model->save();
echo 'data is saved in both tables';
}
$this->render('create',array('verse_model'=>$verse_model,'verse_translation_model'=>$verse_translation_model));
}
In views in create.php
$this->renderPartial('_form',array('verse_model'=>$verse_model,'verse_translation_model'=>$verse_translation_model));
in _form.php
<?php $form = $this->beginWidget('CActiveForm', array('id'=>'verse-form', 'enableAjaxValidation'=>true)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<div class="row">
<?php echo $form->labelEx($verse_model, 'verse_text'); ?>
<?php echo $form->textArea($verse_model, 'verse_text', array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($verse_model,'verse_text'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($verse_model, 'topic_id'); ?>
<?php echo $form->textArea($verse_model, 'topic_id', array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($verse_model,'topic_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($verse_model, 'surah_id'); ?>
<?php echo $form->textArea($verse_model, 'surah_id', array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($verse_model,'surah_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($verse_transaction_model, 'verse_id'); ?>
<?php echo $form->textArea($verse_transaction_model, 'verse_id', array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($verse_transaction_model,'verse_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($verse_transaction_model, 'translations_text'); ?>
<?php echo $form->textArea($verse_transaction_model, 'translations_text', array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($verse_transaction_model,'translations_text'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($verse_transaction_model, 'language_id'); ?>
<?php echo $form->textArea($verse_transaction_model, 'language_id', array('rows'=>6, 'cols'=>50)); ?>
<?php echo $form->error($verse_transaction_model,'language_id'); ?>
</div>
To store in two tables (Model), you have to create two model object for each.
for ex:
$v_model = new Verse; // For save function
$vt_model = new VerseTransctions; // For save function
Pass these model object to view file and use as below.
For verse model text boxes, you have to use:
labelEx($v_model, 'verse_text');
For verse_tarnsction model text boxes, you have to use:
labelEx($vt_model, 'translation_text');
In action (save / update):
$v_model->attributes = $_POST["Verse"];
if($v_model->save())
{ $vt_model->attributes = $_POST["VerseTransctions"];
$vt_model->verse_id = $v_model->id; $vt_model->save();
}
I am quite new in using Yii Fraework and I am trying to implement a custom form with the skeletron from the contact form demo withon the blog demo from Yii Framework. I did almost exactly the same view,, controller and model as the respective form, only that I get the following 500 error:
Error 500
CForm and its behaviors do not have a method or closure named "beginWidget".
Here are the : Controller:
<?php
class CustomController extends Controller {
public function actionSubmit()
{
$model = new CustomForm;
$form = new CForm('application.views.custom._form', $model);
$this->pageTitle = "ffffffffffff";//['title'] = "Authentication";
if($form->submitted('submit') && $form->validate())
$this->redirect(array('blog/index'));
else
$this->render('_form', array('form'=>$form));
}
public function getGenders()
{
return array(
0 => 'Male',
1 => 'Female');
}
}
?>
The Model:
<?php
class CustomForm extends CFormModel {
public $firstName;
public $LastName;
public $phone;
public $address;
public $gender;
public $email;
public function rules()
{
return array(
array('firstName, lastName, gender', 'required'),
array('email', 'email')
);
}
}
?>
The view:
<?php
$this->pageTitle=Yii::app()->name . ' - Custom Form';
$this->breadcrumbs=array(
'Custom Form',
);
?>
<h1>Custom Form</h1>
<?php if(Yii::app()->user->hasFlash('custom')): ?>
<div class="flash-success">
<?php echo Yii::app()->user->getFlash('custom'); ?>
</div>
<?php else: ?>
<p>
If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
</p>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'custom-form',
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'firstName'); ?>
<?php echo $form->textField($model,'firstName'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'lastName'); ?>
<?php echo $form->textField($model,'lastName'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'email'); ?>
<?php echo $form->textField($model,'email'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'phone'); ?>
<?php echo $form->textField($model,'phone',array('size'=>60,'maxlength'=>128)); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'gender'); ?>
<?php echo $form->radioButton($model,'gender',array('value'=>'Male')) . 'Male'; ?>
<?php echo $form->radioButton($model,'gender',array('value'=>'Female')) . 'Female'; ?>
<?php echo $form->error($model,'gender'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'address'); ?>
<?php echo $form->textArea($model,'address',array('rows'=>6, 'cols'=>50)); ?>
</div>
<div class="row submit">
<?php echo CHtml::submitButton('Submit'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
<?php endif; ?>
Any ideas why am I getting this error? What am I doing wrong?
Thanks!
CForm represents a form object that contains form input specifications.
You are passing a view file as parameter to the CForm which wont work.
I guess there is no need for this line:
$form = new CForm('application.views.custom._form', $model);
Please check if it works :)
I have the following form which is being used to create new records
<?php
/* #var $this ComponentsController */
/* #var $model Components */
/* #var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'components-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'component_id'); ?>
<?php echo $form->textField($model,'component_id'); ?>
<?php echo $form->error($model,'component_id'); ?>
</div>
<div class="row">
<label class="required" for="FixedAsset_original_asset_number">
Asset Number
</label>
<input id="Components_original_asset_number" type="text" name="Components[original_asset_number]">
<?php //echo Chtml::textField('fixed_asset_id', FixedAsset::model()->FindByPk($model2->fixed_asset_id)->fixed_asset_id); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'description'); ?>
<?php echo $form->textField($model,'description',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'description'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'manufacturer'); ?>
<?php //echo $form->textField($model,'manufacturer'); ?>
<?php $manufacturer = Manufacturers::model()->findAll(array("order"=>"name"));
$list = CHtml::listData($manufacturer, 'manufacturer_id', 'name');
echo $form->dropDownList($model,'manufacturer', $list,array());
?>
<?php echo $form->error($model,'manufacturer'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'medium'); ?>
<?php //echo $form->textField($model,'medium'); ?>
<?php $medium = Medium::model()->findAll();
$list = CHtml::listData($medium, 'medium_id', 'type');
echo $form->dropDownList($model,'medium', $list,array());
?>
<?php echo $form->error($model,'medium'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'version'); ?>
<?php echo $form->textField($model,'version',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'version'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'serial_no'); ?>
<?php echo $form->textField($model,'serial_no',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'serial_no'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'purchase_date'); ?>
<?php //echo $form->textField($model,'purchase_date'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'id'=>'Components_purchase_date',
'name'=>'Components[purchase_date]',
//'value'=>CTimestamp::formatDate('d/m/Y',$item->validFrom),
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>
<?php echo $form->error($model,'purchase_date'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'disposal_date'); ?>
<?php //echo $form->textField($model,'disposal_date'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'id'=>'Components_disposal_date',
'name'=>'Components[disposal_date]',
//'value'=>CTimestamp::formatDate('d/m/Y',$item->validFrom),
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>
<?php echo $form->error($model,'disposal_date'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'model'); ?>
<?php echo $form->textField($model,'model',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'model'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'nol'); ?>
<?php echo $form->textField($model,'nol'); ?>
<?php echo $form->error($model,'nol'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
I want to send an error to the field Components_original_asset_number on the form. How would I achieve this. In the controller function I am checking to see if it exists if not I want to display error on form or message. original asset number is part of a separate model which I am displaying on this form.
public function actionCreate()
{
$model = new Components;
$model_fixedAsset = new FixedAsset;
$model_comAsset = new ComAsset;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Components']))
{
$model->attributes=$_POST['Components'];
$fixedAssetId = null;
// Check if asset exist and get PK
if( $_POST['Components']['original_asset_number'] != "" ){
//print_r($_POST['Components']);
$criteria = new CDbCriteria;
$criteria->condition = "(original_asset_number = :original_asset_number)";
$criteria->params = array(":original_asset_number" => $_POST['Components']['original_asset_number'] );
$fixedAssetRow = FixedAsset::model()->find($criteria);
//print_r($fixedAssetRow);
if($fixedAssetRow){
$fixedAssetId = $fixedAssetRow->fixed_asset_id;
}
//echo $fixedAssetId;
}
if($fixedAssetId){
/*if($model->save())
$this->redirect(array('view','id'=>$model->component_id));*/
// Create com_asset record
}else{
//no asset found return error message to input corect asset number or create asset in navision and run php script to update mysql db
}
}
$this->render('create',array(
'model'=>$model,
'model_fixedAsset'=>$model_fixedAsset,
'model_comAsset'=>$model_comAsset,
));
}
You should add the 'original_asset_number' in your model as variable and set required validation rule. Then you can use the following line to set error
$model->addError('original_asset_number', " no asset found return error message to input corect asset number or create asset in navision and run php script to update mysql ");
Also, you use the following way to display the field and error.
<?php echo $form->errorSummary($model); ?>
or
<div class="row">
<?php echo $form->labelEx($model,'original_asset_number'); ?>
<?php echo $form->textField($model,'original_asset_number',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'original_asset_number'); ?>
</div>