Auto Assign Values in entry form

By: BRUCE DAFEAMEKPOR | Asked: 07/29/2023
ForumsCategory: General questionsAuto Assign Values in entry form
BRUCE DAFEAMEKPORBRUCE DAFEAMEKPOR asked 10 months ago
I need help to setup an online entry form that will automatically assign one of certain 4 unique values to a user. Scenario: Students applying to a school are shown their "Houses" automatically on the entry form(read only). The school has four houses that are randomly assigned to students. Please help
4 Answers
Rob LeVineRob LeVine answered 10 months ago
User frm_setup_new_fields_vars to initialize the value of the field.
BRUCE DAFEAMEKPORBRUCE DAFEAMEKPOR replied 10 months ago

Okay. Thank you
I need to read ore on that

BRUCE DAFEAMEKPORBRUCE DAFEAMEKPOR answered 7 months ago

I need further help as a newbie. Please help me get this done.T_T  Reality: I have four options in a drop down. (ie Adzotor, Xalavia, Gbogbi, Gbekor) Kindly edit the code and paste here to auto assign any of this Houses based on this sequence (Adzotor, Xalavia, Gbogbi, Gbekor) per submission. I have tried but to no avail

Rob LeVineRob LeVine replied 7 months ago

Sorry, but this forum isn't really about writing code for people. I suggest you reach out to a developer to help - https://formidable-masterminds.com/developers-directory/

Michael ClarkMichael Clark replied 7 months ago

Here's some sample code from the Formidable Forms documentation That I've adapted below as a starting point. Hope it helps.

https://formidableforms.com/knowledgebase/frm_validate_field_entry/#kb-round-robin-assignments

Michael ClarkMichael Clark answered 7 months ago

A potential solution could be based on a "round robin" method where some custom code assigns the house The code provided here is adapted from the "Round robin assignments" example in the Formidable Forms documentation for its built-in frm_validate_field_entry function 1. Create a read-only text field with a default value of [auto_id]. Note the field ID. 2. Set that field visibility to admin-only in the advanced settings 3. Create another admin-only text field where the house name is stored. Note the field ID. 4. Use the following code snippet in either a code snippet plugin or the site's function.php, and change the values where noted in the code's comments to suit your needs. 5. Create Views for tracking the entries and for sending out housing assignment notifications, or for use in form Confirmation settings.

add_filter( 'frm_validate_field_entry', 'frm_set_house_based_on_order', 15, 3 );
function frm_set_house_based_on_order( $errors, $posted_field, $posted_value ) {
   if ( $posted_field->id == 175 ) { //change 175 to the ID of your house name field
      $house_id   = $_POST['item_meta'][174] % 4;//change 174 to your auto_id field and 4 to the number of houses you have
      $house_name = "unassigned";//change "unassigned" to your default value
      switch ( $house_id ) {
         case 0: 
            $house_name = "house-01";//change "house-01" to the name of your house
            break;
         case 1:
            $house_name = "house-02";//change "house-02" to the name of your house
           break;
         case 2:
            $house_name = "house-03";//change "house-03" to the name of your house
           break;
         case 3:
            $house_name = "house-04";//change "house-04" to the name of your house
           break;
      }//add additional cases for additional groups, as you'd like
      $_POST['item_meta'][175] = $house_name;//change 175 to the ID of your house name field
   }

   return $errors;
}

 

Michael ClarkMichael Clark replied 7 months ago

sorry for the wierd formatting, I can't get the text field in this forum to make line breaks :pouting:

Victor Font replied 7 months ago

When posting code blocks, it's easier to post on pastebin or gist and include the link here.

BRUCE DAFEAMEKPORBRUCE DAFEAMEKPOR answered 7 months ago
Thank you so much for this intervention  
BRUCE DAFEAMEKPORBRUCE DAFEAMEKPOR replied 7 months ago

I have a further one
Using the same method, please help assign certain houses to students based on their gender

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right