I really don’t know what is wrong with this script.. I really thought everything was right, but somehow my strpos syntaxs doesn’t work properly or something. The $_POST['category'] is a select list with multiple selections permitted. So that’s why I put it in an array, but maybe it is incorrect?
$cat_array = $_POST['category'];
foreach($cat_array as $key => $value )
{
if(strpos($value, 'n_') !== false)
{
// Do something about the new categories.
} else {
// work with existing categories
}
}
the html – I also have a jquery that handles the add category fields. The n_(number)-(value) is created by jquery.
<div>
<label for="category">Category</label>
<select name="category" size="10" multiple="MULTIPLE">
<option class="cat_1" value="1">Cars</option>
<option class="cat_2" value="2">Lego</option>
<option class="cat_3" value="3">Country</option>
<option class="cat_4" value="4">School</option>
<option class="cat_5" value="5">Cooking</option>
<option class="cat_6" value="n_6-test">test</option>
<option class="cat_7" value="n_7-Buuh">Buuh</option>
</select> <br>
<input type="text" name="new_cat" value="" size="40" maxlength="120" placeholder="Category Name"><input class="plus" name="" type="button" value="Add Category">
<p class="plus_comment"></p>
</div>
To make your category actually an array you have to append brackets to the category like this:
category[]So your HTML woul look like this