• Resolved Mario Z.

    (@maze233)


    Hi Roland,

    This question is a follow up from this thread.

    How do you insert information a user enters on a signup form to the database when the submit button is pressed?

    In the thread linked above you helped me creating a custom dropdown field and now im struggling arround to get that selected value back to the database as soon as the submit button is pressed.

    At the moment I have this code for my custom dropdown:

    <?php
    global $wpdb;
    $field = 'activity_title';
    $activities = array();
    // grab the unique stored values from the field
    $result = $wpdb->get_results('SELECT DISTINCT p.' . $field . ' from ' . Participants_Db::$participants_table . ' p WHERE p.' . $field . ' <> "" AND p.approved ="yes"', ARRAY_N);
    // now we convert the query result into a simple array
    foreach($result as $value) {
      $activities[] = current($value);
    }
    // print the dropdown
    echo PDb_FormElement::get_element(array(
        'name' => 'selected_activity',
        'type' => 'dropdown',
        'options' => $activities
            )
        );
    ?>

    To get the information from the selected dropdown value back to the database I was starting to use code like this:

    $table_name = Participants_Db::$participants_table;
    $wpdb->insert($table_name, array('activity_title' => $_POST['selected_activity']));

    Can you help me that the selected value from the dropdown is inserted to the database when the submit button is pressed?

    Thanks and regards,
    Mario

    https://ww.wp.xz.cn/plugins/participants-database/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Roland Barker

    (@xnau)

    No need to do any of that, just create a field with the name that matches the dropdown name (selected_activity), and the data will be saved with everything else.

    Thread Starter Mario Z.

    (@maze233)

    So simple….
    Was already thinking way too far.

    Thanks a lot!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Insert value to database on signup’ is closed to new replies.