• Resolved Sonika

    (@sonika)


    My site contains 60 hotels (custom post type, but i think it is not important for this question).

    So I need a “booking” form for every hotel, but i dont want to create 60 forms, it is easy but very stupid way 🙂

    The form has standard fields for each hotel, so i need only one form to use.

    The problem is: every hotel has own list of rooms, and I want to create custom field “roomtypes” with multiple custom fild values, and somehow input this custom fild values in form like options in selectbox.

    The form will be inserted on every hotel page.

    I had a look in function insert_custom_cform, but didnt find what I want. And internet didnt help.

    I’m not a programmer, please I need help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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?

    Plugin Author bgermann

    (@bgermann)

    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.
    Plugin Author bgermann

    (@bgermann)

    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!!!

    1

    I think it will be very useful topic for cforms users!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Dinamicaly insert custom fields values in cforms fields’ is closed to new replies.