Forums | Mahara Community

Developers /
Hide form elements by radio button


anonymous profile picture
Account deleted
Posts: 15

10 December 2014, 3:09

Hi all,

I'm having two option when selecting second radio button i want to hide three text box and show links instead.

this is $form

'name' => 'testform',
'method' => 'post',
'action' => '',
'elements' => array(
'invite_options' => array(
'type' => 'radio',
'title' => 'Invite Options',
'defaultvalue' => 'option_one',
'options' => array(
'option_one' => 'Invite By Email',
'option_two' => 'Multiple emails',
),
),

'name' => array(
'title' => 'Name',
'type' => 'text',
'name' => 'input_name',

),
'mail' => array(
'title' => 'Email',
'type' => 'text',
'name' => 'input_email',

),
'content' => array(
'type' => 'textarea',
'title' => 'Content',
'description' => 'Enter some content to send in email',
'name' => 'input_content',
'rows'=>'4',
'cols'=>'50'
)

)

Now is there any way to insert div for elements so that i can use jquery to hide and show.

OR..

I found in wiki:

function form_render_text($element, $form) {
    return '         . Form::element_attributes($element)
        . ' value="' . hsc($form->get_value($element)) . '">';
}

Could i use this function?

 

anonymous profile picture
Account deleted
Posts: 112

22 December 2014, 9:43

One solution would be to assign the text boxes to be "readonly" when you don't want the user to enter in data.  Otherwise set them to readonly=:"false".

'readonly' => 'true',

Another option would be to put the three text boxes into a fieldset.  Then set the class of the fieldset to be "hide" (css code of display:none;). -- when you don't want them to be displayed.  And just leave off the class when you do want them to be displayed.

 'class' => 'nodisplay';

Then the css file says

.nodisplay {

   display:none;

}

2 results