boionfire81 Posted June 23, 2016 Posted June 23, 2016 Since I have so many areas that need a member id input for action, I'm wanting to duplicate the Torn style member dropdown function. Anyone up for the challenge? Quote
Dave Posted June 23, 2016 Posted June 23, 2016 This is quite straight forward, what's your budget on this? Quote
SRB Posted June 24, 2016 Posted June 24, 2016 Dave is correct - it's simple enough. jQuery - jQuery UI - autocomplete Single Ajax call Quote
Magictallguy Posted June 28, 2016 Posted June 28, 2016 You'll need to import the jquery-ui.css and a jquery.js function getList($var = false, $value = false) { global $db; $selectUsers = $db->query('SELECT `username` FROM `users` ORDER BY `username` ASC'); $users = []; while($row = $db->fetch_row()) $users[] = $row['username']; ?><script> $(function() { var availableUsers = <?php echo json_encode($users);?>; $( "#users" ).autocomplete({ source: availableUsers }); }); </script><?php if($var) { $ret = '<div class="ui-widget">'; $ret .= '<input id="users"'; $ret .= ' name="'.$var.'"'; if($value) $ret .= ' value="'.$value.'"'; $ret .= ' autofocus />'; return $ret; } } Usage (as part of a form): Returns an input box with a list of all users, with a $_REQUEST (_POST/_GET) named data_name_for_form. echo getList('data_name_for_form'); Returns an input box with a list of all users, request data named user, automatically filled with $value //Assuming getdata has been sanitized $selectUser = $db->query('SELECT `username` FROM `users` WHERE `userid` = '.$_GET['id']); $value = $db->num_rows($selectUser) ? $db->fetch_single($selectUser) : null; echo getList('user', $value); I'll take that $50, if that's still going, thanks. Quote
boionfire81 Posted July 3, 2016 Author Posted July 3, 2016 Ok, going to be working on this today. [uSER=53425]Magictallguy[/uSER] :) Where do I obtain the jquery-ui.css and a jquery.js? Or is that the same as what is included in the mcc jquery1.7.1.min.js? Quote
Magictallguy Posted July 3, 2016 Posted July 3, 2016 The MC Craps version of jQuery *should* suffice. As for the UI, https://code.jquery.com/ui/1.11.4/jquery-ui.min.js is what you're after Quote
boionfire81 Posted July 3, 2016 Author Posted July 3, 2016 Usage (as part of a form): Returns an input box with a list of all users, with a $_REQUEST (_POST/_GET) named data_name_for_form. echo getList('data_name_for_form'); Returns an input box with a list of all users, request data named user, automatically filled with $value //Assuming getdata has been sanitized $selectUser = $db->query('SELECT `username` FROM `users` WHERE `userid` = '.$_GET['id']); $value = $db->num_rows($selectUser) ? $db->fetch_single($selectUser) : null; echo getList('user', $value); Ok, can you explain what the code is I'm looking at here, and how/what should be modified if any? Quote
Magictallguy Posted July 3, 2016 Posted July 3, 2016 Here's an example of it in a form designed to send an event to a user. <?php require_once __DIR__ . '/globals.php'; // If the form has been submitted if(array_key_exists('submit', $_POST)) { // Basic sanitation $_POST['user'] = array_key_exists('user', $_POST) && is_string($_POST['user']) ? $db->escape(trim($_POST['user'])) : null; $_POST['event'] = array_key_exists('event', $_POST) && is_string($_POST['event']) ? trim($_POST['event']) : null; // Basic validation if(empty($_POST['user'])) { echo 'You didn\'t select a valid user'; exit($h->endpage()); } if(empty($_POST['event'])) { echo 'You didn\'t enter a valid event text'; exit($h->endpage()); } // Get the user $select = $db->query('SELECT `userid` FROM `users` WHERE `username` = "'.$_POST['user'].'"'); // Does the user exist? if(!$db->num_rows($select)) { echo 'The user you selected doesn\'t exist'; exit($h->endpage()); } // Return the userid $user = $db->fetch_single($select); // Send the event event_add($user, $_POST['event']); echo 'The event has been sent<br />'; } // Display the form ?><form action="send_event.php" method="post"> <table class="table" width="100%"> <tr> <th width="25%">User</th> <td width="75%"><?php echo getList('user');?></td> </tr> <tr> <th>Event</th> <td><input type="text" name="event" /></td> </tr> <tr> <td colspan="2" class="center"><input type="submit" name="submit" value="Send Event" /></td> </tr> </table> </form><?php // Page footer $h->endpage(); If you were to stick that in a file called send_event.php, you'd be able to simply start typing a name to select a user. With the way the getList() function works, it'll return a username as the value so, we select the user based on the username entered. If the user doesn't exist, end the page. If the user does exist, return their respective userid and continue. Long story short; getList() returns a username as a value. Do with it as you wish ;) Quote
boionfire81 Posted July 3, 2016 Author Posted July 3, 2016 All it is displaying is a plain input text box. Quote
boionfire81 Posted July 3, 2016 Author Posted July 3, 2016 if(!$_POST['user']) { echo "<br /><form action='trade.php' method='post'> Please type the ID# of the user you wish to trade with below.<br /><br /> ".getList('user')." <input type='submit' value='Send Request' class='button'/> </form><br /><a href='index.php' class='button'>Exit</a>"; } TC allows a drop-down that shows your friends list, faction members, company, etc. to help for quick selection. A plain text input would be a simple db query to change the username to and id before processing. Quote
Magictallguy Posted July 3, 2016 Posted July 3, 2016 Indeed. We can therefore assume that the stock jQuery packaged with MC Craps is no good. Try using the latest jQuery found here Quote
Magictallguy Posted July 4, 2016 Posted July 4, 2016 I've tested this myself, it does work. I'd have to see your setup before I can diagnose further - feel free to shoot me a PM Quote
boionfire81 Posted July 4, 2016 Author Posted July 4, 2016 sent, let me know if you need any further details. Quote
Magictallguy Posted July 9, 2016 Posted July 9, 2016 You appear to have a conflicting js imported in. Suggestion: Strip out *all* from the header. Add them back 1-by-1, starting with the JS required for the getList() (sent via PM). Once it stops working, you know which one is conflicting Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.