In our little town we have a (1945fair.com) fair each year so that local homebased businesses have a place to show and sell their wares. I am the web developer (78 years old and forgetful) and I was asked to make a way the 85 spaces could be assigned without different people being assigned the same space. I thought I can do that! I used Unique in a number field and set it to 0 to 85 with steps of 1. The issue is the folks that need to assign the space need to change assignments from time to time. For example, if someone makes green widgets and they have space 3 and later another person wants a space and only 2 and 4 are available, and they also makes green widgets, we don not want them next to each other. I guess this takes javascript or php or something else over my head to make it were a space can be changed and when it is changed the "old" number goes back into a pot for reassignment to someone else. I attached the form I was working with. Anyone that can help is greatly appreciated.
I got the part to work that prevents the same space being assigned to different people. I am using two spaces as a maximum for spaces for one person. I installed the Woody plugin so I could use the php code below. I created a short cut via Woody for the php code and pasted in the page. I have gtwo fields that are Unique from 1 - 99.
What I would like to understand is where is the information stored and how could I delete a space that has been assigned (spaces get moved around to accomodate not having two person with the same thing next to each other)
add_filter('frm_validate_field_entry', 'two_fields_unique', 10, 2);
function two_fields_unique( $errors, $posted_field ) {
$first_field_id = 125; // change 125 to the id of the first field
$second_field_id = 126; // change 126 to the id of the second field
if ( $posted_field->id == $first_field_id ) {
$entry_id = isset( $_POST['id'] ) ? absint( $_POST['id'] ) : 0;
$values_used = FrmDb::get_col( 'frm_item_metas',
array( 'item_id !' => $entry_id,
array( 'or' => 1,
array( 'field_id' => $first_field_id, 'meta_value' => $_POST['item_meta'][ $first_field_id ] ),
array( 'field_id' => $second_field_id, 'meta_value' => $_POST['item_meta'][ $second_field_id ] ),
)
), 'item_id', array( 'group_by' => 'item_id', 'having' => 'COUNT(*) > 1' )
);
if ( ! empty( $values_used ) ) {
$errors[ 'field'. $first_field_id ] = 'You have already selected that option';
$errors[ 'field'. $second_field_id ] = 'You have already selected that option';
}
}
return $errors;
}
I have absolutely no idea what the Woody plugin is or what it's used for.
You said, "What I would like to understand is where is the information stored and how could I delete a space that has been assigned"
All entry details are stored in two tables. frm_items and frm_item_metas. Your code snippet above doesn't actually do much except check if the values exist in frm_item_metas, which is where all the metadata is stored.
The $_POST object is a PHP associative array. It's not stored anywhere. It's in memory only. It's the carrier for all form data transferred between the browser and the server when the form is submitted.
Explaining how to delete a space and reassign it isn't possible without a deep understanding of your system design. And it's way more information than can be conveyed in a string of forum messages. If you have budget, you may want to consider consulting with a software engineer to make sure you're going down the most efficient path with your design.
I also support small community events and completely relate to the challenges. I've made self-serve event registration, management, and ticketing systems for professional associations, community car shows, golf tournaments, and other fundraising efforts.
Reply here if you still want additional help getting this dialed in, I may have already made something that can be adapted to your needs. If not, I'll consider carving out some volunteer time to your effort. 🙂
Wow! Sorry to hear you haven't been well Harry. It's been a month since you posted. Glad to hear you're doing better. I wish you a full recovery if you're still on the mend.
Michael has my vote of confidence on helping you sort this one out. I just popped in to say high when I saw you were ill.
@Harry Abell: So, @Victor Font should know because he's taught me nearly everything that's missing from the documentation. 🙂
Please login or Register to submit your answer