Forums | Mahara Community

Developers /
I want to create form containing radio buttons with Pieforms


24 May 2017, 20:30

Hello.

I need to Create form containing radio buttons with Pieforms.

I tried this code. I looked at the code on Pieform's reference.

 

```

$pieform_elements = array(
'login' => array(
'type' => 'fieldset',
'legend' => get_string('login'),
'elements' => array(
'login_username' => array(
'type' => 'radio',
'title' => get_string('username'),
'description' => get_string('usernamedesc'),
'help' => get_string('usernamehelp'),
'rules' => array(
'required' => true
)
),
'login_password' => array(
'type' => 'password',
'title' => get_string('password'),
'description' => get_string('passworddesc'),
'help' => get_string('passwordhelp'),
'value' => '',
'rules' => array(
'required' => true
)
)
)
),
'submit' => array(
'type' => 'submit',
'value' => get_string('login'),
'class' => 'btn-primary'
)
);


$form = pieform(array(
'name' => 'testform',
'method' => 'post',
'action' => '',
'elements' => $pieform_elements,
));

```

 

I changed 

'type' => 'text',

to

'type' => 'radio',

but, not working.

 

Is there a source code or URL that is a hint of how to make it?

Thanks for your help.

Nakanishi,

Cecilia Vela's profile picture
Posts: 110

25 May 2017, 8:53

Hello Tetsuhiro,

In order to use a pieform with type 'radio' you need to define the options to display.

Try replacing the login_username part with this code:

'login_username' => array(
'type' => 'radio',

'options' => array(
0 => 'option 1',
1 => 'option 2',
2 => 'option 3',
),


'title' => get_string('username'),
'description' => get_string('usernamedesc'),
'help' => get_string('usernamehelp'),
'rules' => array(
'required' => true
)
),

 

Hope this helps!

Cecilia

25 May 2017, 11:20

Thanks for replying!

It worked perfectly!

I really appreciate your help!

Nakanishi

Noraini's profile picture
Posts: 13

12 October 2017, 16:55

What if my code like this. how to set type radio button?

i call field from function :

$element_list = ArtefactTypeProfile::get_all_fields();

Then in the function located at artefacts/internal/lib.php :

$out = array(
            'firstname'       => 'text',
            'lastname'        => 'text',
            'studentid'       => 'text',
            'preferredname'   => 'text',
            'introduction'    => 'wysiwyg',
            'email'           => 'emaillist',
            'officialwebsite' => 'text',
            'personalwebsite' => 'text',
            'blogaddress'     => 'text',
            'address'         => 'textarea',
            'town'            => 'text',
            'city'            => 'text',
            'country'         => 'select',
            'homenumber'      => 'text',
            'businessnumber'  => 'text',
            'mobilenumber'    => 'text',
            'faxnumber'       => 'text',
            'occupation'      => 'text',
            'industry'        => 'text',
            'maildisabled'    => 'html',
            'phylosophy'      => 'text',
            'vision'          => 'text',
            'mission'         => 'text',
            'job_interest'    => 'textarea',
            'age'             => 'text',
            'gender'          => 'radio',
        );

 

If i set type like above, error display.

Kristina Hoeppner's profile picture
Posts: 4863
5 results