http://loopj.com/jquery-tokeninput/の jQuery Tokeninput オートコンプリート プラグインを使用し ています
HTML
<form action="<?=base_lang_url("addtags/test")?>" method="post">
<input id="tags" name="tags">
<input type="submit" value="Add">
</form>
JS
$('#tags').tokenInput("../ajax/getTags", {
allowCustomEntry: true,
propertyToSearch: "name",
tokenValue: "name",
tokenLimit: 5,
preventDuplicates: true,
theme:"facebook",
noResultsText: "No results",
searchingText: "Searching..."
});
JS は、どのように設定したかを示すだけですが、これはそれほど重要ではないと思います。
PHP
if(trim($this->input->post("room_tags")) != ""){
$tags = explode(",",trim($this->input->post("room_tags")));
foreach($tags as $value){
if(preg_replace( "/[^0-9]/", "",$value)){
$tag_int[] = $value;
}else{
$tag_string[] = $value;
}
}
$this->load->model("tags_model");
$tag_find = $this->tags_model->findTags($tag_int);
if(is_array($tag_find) && is_array($tag_string)){
$all_tags = array_merge($tag_find,$tag_string);
}elseif(is_array($tag_find) && isset($tag_find)){
$all_tags = $tag_find;
}elseif(isset($tag_string) && is_array($tag_string)){
$all_tags = $tag_string;
}
echo "<pre>";
echo print_r($all_tags);
echo "</pre>";
}
結果
Array
(
[0] => Array
(
[tag_name] => Hej
)
[1] => Array
(
[tag_name] => Hvor
)
[2] => Array
(
[tag_name] => Hvad
)
[3] => 'wegehe'
[4] => 'afqfq'
)
私はこのようにするのが好きです:
Array
(
[0] => Hej
[1] => Hvor
[2] => Hvad
[3] => wegehe
[4] => afqfq
)
文字列に ' なし。
誰かが助けてくれることを願っています:)