Thread Starter
Sonika
(@sonika)
ADD:
So i have
<?php $roomtypes = get_post_meta($post->ID, 'roomtypes', false); ?>
<select>
<?php foreach($roomtypes as $roomtype) { echo '<option>'.$roomtype.'</option>'; } ?>
</select>
And i get:
<select>
<option>Standard</option><option>Lux</option><option>Suite</option>
</select>
How to put this values in cforms’ form?
You find the documentation for insert_custom_cform
at the plugin’s help section under “Advanced: Real-time creation of dynamic forms”. However the function will be deprecated with version 14.14 in favour of insert_cform
, which provides the same feature set. You can do it like this:
$sb_label = 'Selectbox Label';
foreach($roomtypes as $roomtype) {
$sb_label .= '#' . $roomtype;
}
$base_cform_id = '';
$labels = [ $sb_label, "Foo Field's Label", "Bar Field's Label" ];
$types = [ 'selectbox', 'textfield', 'textfield' ];
$dynamic_fields = [ 'label' => $labels, 'type' => $types ];
/* You can also extend $dynamic_fields with isreq, isemail, isclear, isdisabled, isreadonly */
insert_cform($base_cform_id, $dynamic_fields, '+'); /* In ver 14.14 you can leave out the '+'. */
-
This reply was modified 6 years, 10 months ago by bgermann.
Thread Starter
Sonika
(@sonika)
@bgermann, THANKS a lot!
Excellent decision for me!
Sorry for the arrogance, but how to make some fields in this form “with isreq, isemail, isclear, isdisabled, isreadonly”?
In fact I need some “textfild” fields marked as “required”, it will be enough for me.
In FAQ sections there are some examples, but the form’s output has another format
-
This reply was modified 6 years, 10 months ago by Sonika.
You set the is… like the label and type.
$sb_label = 'Selectbox Label';
foreach($roomtypes as $roomtype) {
$sb_label .= '#' . $roomtype;
}
$base_cform_id = '';
$labels = [ $sb_label, "Foo Field's Label", "Bar Field's Label" ];
$types = [ 'selectbox', 'textfield', 'textfield' ];
$req = [ false, true, true ];
$email = [ false, false, false ];
$clear = [ false, false, false ];
$diabled = [ false, false, false ];
$readonly = [ false, false, false ];
$dynamic_fields = [
'label' => $labels, 'type' => $types,
'isreq' => $req, 'isemail' => $email,
'isclear' => $clear, 'isdisabled' => $disabled,
'isreadonly' => $readonly
];
insert_cform($base_cform_id, $dynamic_fields, '+');
Thread Starter
Sonika
(@sonika)
@bgermann, THANKS!!!
I think it will be very useful topic for cforms users!