Hidden button

I have 2 buttons at the same form.

I want to hide a button in an alternative way one button or the other … how could I do?

You can give a unique ID to the buttons and then use jQuery to hide/show them…

for more help you need to show how you create the buttons and what would be the first view (both buttons visible, or only one of them)

My code is:

<div class="row buttons" >

<?php echo CHtml::submitButton(‘Inserimento Docente’, array(‘submit’ => ‘/tirocini/index.php?r=docente/create&id=’.$model->ANAGRA_ID.’’)); ?>

<?php echo CHtml::submitButton(‘Inserimento Studente’, array(‘submit’ => ‘/tirocini/index.php?r=studente/create&id=’.$model->ANAGRA_ID.’’)); ?>


You haven’t explained the exact need, from the button source I understand that you need only one button depending if you are adding DOCENTE or STUDENTE but where is defined what are you adding? or How to know what button you want?

Do you have two different controllers (docente and studente) that calls the same view?

P.S. when you insert your code enclose it with the [ code ] tag… like this: [code ]… your code… [/code ]

([code ] - without spaces

Yes I have 2 different controller STUDENTE_CONTROLLER and DOCENTE_CONTROLLER

My situation is that:

I initially have a menu choice where I choose to list a student or teacher.

The problem is that the initial form of both is the same with that is completed by entering the personal details of the person from whom I bring ANAGRA_ID.

Now even after I entered the data in the db I load a new form depending on whether I enter a student or teacher.

And here I want to hide a button depending on who I need to enter.

How can I do?

So before rendering the view with the buttons you know if it’s a STUDENTE or DOCENTE and you can send additional variable to the view like



            'tipo'=>'STUDENTE',   //.. or you can use only first letter like 'tipo'=>'S'


*note the use of the [code ] for more readable code in the forum

now in the view you can use a simple

if($tipo=="STUDENTE")  //.. or $tipo=="S"

   button for studente


   button for docente

Sorry but I did not understand a thing …

‘Type’ => ‘STUDENT’, … in this line of code STUDENTE does not refer to a field in the student model…but is a random string … … right?

Actually I have written ‘tipo’ not ‘type’… that will become a variable ($tipo) in the view that you can use/test

‘STUDENTE’ is a string value that $tipo will have… and that you can test in the view…

Please read the definitive guide to Yii… http://www.yiiframew…ide/basics.view

Ok I have tried but not work correctly…

Display always the ‘docente’ button,but never the ‘studente’ button

The problem for me is that not know before clik button if is student or teacher and so not enter in the if condition and display always the else condition…

In previous form there is no field in which you can tell whether I want to insert a student or teacher…

this code:





doesn’t work if I put the controller student or in the controller of the previous form Anagrafe_controller…I do not know if I was clear

OK I understand that… but then you need to explain me when/where/how do you know if it’s a DOCENTE or a STUDENT…

how else can you decide which button to display…

Good question … … are days that I think on how.

I do not know how to proceed.

I decide (Administrator) to insert a teacher or a student … the problem is that I am forced to put two buttons and I somehow hide either.

Let’s say I have the previous form only your name, address and sex that are required and anagra_id that use the GET to use the same id.

I really do not know how to do …help meee

I can’t help you…

If only you can decide (administrator) if it’s STUDENTE or DOCENTE than how can a program know what button to show/hide?