April 23, 20187 yr I have a projects DB where I am applying "tags" via a multiple checkbox field. I would like to make this field available on the webpage for searches to find the relevant projects. I was successful using a text box field but it would be much more user friendly to have checkboxes of available tags. As time goes on, the tags list may grow. So my question is how would I code the value list options as checkboxes into a search field on the web. My code works for the text field and a single checkbox but not multiple checkboxes. I tried to create a search array using some manual entries and $find = $_POST['search','search1'] but this didn't seem to work. In any event I don't wish to code the options and I would like the list to be dynamic to reflect the Value list which only give values found in that field. In the code below $options are the values that I would like the checkboxes to be. You can see the results at arina.biz/phptest.php I have attached the whole code for reference. /*================================================================ * * Get list of Tagss before creating the form * *=================================================================*/ $cmd =& $connection->newFindCommand('WebSearch'); $cmd->addFindCriterion('seachvaluelist', '*'); $result1 = $cmd->execute(); $records = $result1->getRecords(); $record = $records[0]; //the GET VALUE COMMAND $options = $record->getField("seachvaluelist"); Echo 'Enter key words and click <b>SUBMIT</b> (or <b>RETURN</b> key)<br><br><br>'; echo 'Choose from… '.$options.'<br><br>'; Echo 'Separate multiple Key words with a space.<br>'; ?> <form action='phptest.php' method="post" enctype="multipart/form-data"> <input type="text" name="search"><br> <input type="checkbox" name="search" value="Anatomy"> <label for="search">Anatomy</label><br> <input type="checkbox" name="search1" value="STEM"> <label for="search1">STEM</label><br> <input type="checkbox" name="search2" value="Laboratory"> <label for="search2">Laboratory</label><br> <input type="checkbox" name="search3" value="Informallearning"> <label for="search3">Informal learning</label><br> <input type="submit"> </form> <?php /* =================================================================== search and print ===================================================================*/ $find = $_POST['search']; Edited April 24, 20187 yr by Aussie John updated the PHP
April 24, 20187 yr Author I have found this snippet which gives me what I want but I dont seem to be able to get the selections to find. I suspect checking the box and hitting submit doesn't parse the actual text value. Any suggestions for this? $layout =& $connection->getLayout('WebSearch'); $values = $layout->getValueList('SearchTags'); foreach($values as $value){ echo '<input type= "checkbox" name= "SearchTags" value= "'. $value .'">' . $value . ' '; } Edited April 24, 20187 yr by Aussie John Discovered the error: $FM should have been $Connection
April 24, 20187 yr Hi John The getValueList method is deprecated and replaced with getValueListTwoFields. See the API documentation on your server for details.
April 26, 20187 yr Author Thank IdealData. Point noted but I am still having trouble getting the result of the checkbox selections. Using the text box for the search returns a result but using the checkboxes doesn't. see arina.biz/phptest.php Any thoughts? $layout =& $connection->getLayout('WebSearch'); $values = $layout->getValueList('SearchTags'); foreach($values as $value){ echo '<input type= "checkbox" name= "Search" value= "'. $value .'">' . $value . ' '; } // echo "<br>search"; //=========================================================== ?> <form action='phptest.php' method="post" enctype="multipart/form-data"> <input type="text" name="Search"> <input type="submit"> <br> </form> <?PHP /* =================================================================== Print ===================================================================*/ $find = $_POST['Search']; echo "Last search was for… <b>$find</b>";
April 26, 20187 yr You need to make the names of the checkbox inputs part of an array, and then use the newCompoundFindCommand() in the php api. I am assuming that since you are using check boxes instead of Radio buttons, you foresee the need to select multiples. See if these help. You will have to put them on your servers and massage the paths a bit, of course. checkbox.zip
April 26, 20187 yr Author Thanks Doughemi You put a lot of effort in to your response and that was very helpful. Edited April 26, 20187 yr by Aussie John
Create an account or sign in to comment