Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8743155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:37:37+00:00 2026-06-13T11:37:37+00:00

I have the following form which is being used to create new records <?php

  • 0

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,
    ));
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:37:38+00:00Added an answer on June 13, 2026 at 11:37 am

    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>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following jQuery code: $(.save_button).click(function() { var $form = $(this).closest(div.info_section).find(form); url =
I have the following form for photo_album which uses the nested forms feature of
I have the following form, which I have reduced as much as I can,
I have the following text input on a budget calculator form which displays the
Hi I have a visual studio project which includes postbuildevents in the following form:
I have the swiss data set provided by R, which has the following form:
I have the following code, which should adds a field to a form if
I have a form with id theForm which has the following div with a
I have a C# windows application which does the following: 1) the main form
I have a simple MVC form with the following elements: <%= Html.TextBox(FechaInicio) %> Which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.