Php 提交表单后将类添加到链接

Php 提交表单后将类添加到链接,php,sql,forms,Php,Sql,Forms,根据用户选择的选项,我试图在提交表单后添加一个类 <form enctype="multipart/form-data" action="upload.php" method="POST"> title:<br /> <input type="text" name="title" value="" /> <br /> description:<br /> <input type="text" n

根据用户选择的选项,我试图在提交表单后添加一个类

<form enctype="multipart/form-data" action="upload.php" method="POST">
    title:<br /> 
    <input type="text" name="title" value="" /> <br />
    description:<br /> 
    <input type="text" name="description" value="" /> <br />
    Categories:<br /> 
    <input type="checkbox" name="categories[]" value="1">Landscpae<br />
    <input type="checkbox" name="categories[]" value="2">Portrait<br />
    <input type="checkbox" name="categories[]" value="3">Monochrome<br />
    Please choose an image: <input name="uploaded" type="file" /><br />
    <input type="submit" value="Upload" />
</form> 


<li class='INSERT OPTION HERE'> test </li>

标题:

说明:

类别:
Landscpae
肖像画
单色
请选择一个图像:
  • 测试
  • 使用选项选择多个类,以便在每个类之后添加一个空格。 在我的数据库上,Value=“1”2“3”==选项名称


    如果需要更多信息,请告诉我

    您希望确保提交了表单,如果是,则您将回声一个类,并可以创建一个开关语句,该语句将根据所选内容更改类

    <li 
    <?php 
    if(isset($_POST['categories']))  {
    echo 'class="';
    switch($_POST['categories']) {
    case 1;
    echo 'class1';
    break;
    case 2;
    echo 'class2';
    break;
    case 3;
    echo 'class3';
    break;
    echo '"';
    }
    }
    ?> 
    > test </li>
    

    遵循以下思路可能会奏效:

    $valid = array(1,2,3);#valid items
    if(isset($_POST['categories']) && is_array($_POST['categories'])){
        $post = array_unique($_POST['categories']);#you might not need this, but this removes duplicate values
        foreach($post as $key => $value){
            if(in_array($value, $valid)){
                $class = true;
            }else{
                unset($post[$key]);#remove bad values, also this may not be necessary but removes unwanted items.
            }
        }
        if(isset($class)){
            $class = 'class="class' . implode(' class', $post) . '"';
        }
    }#else needed for non array categories?
    
    <li <?php if(isset($class)){ echo $class;} ?> > test</li>
    
    $valid=array(1,2,3)#有效项目
    if(isset($\u POST['categories'])和&is_数组($\u POST['categories'])){
    $post=array_unique($_post['categories']);#您可能不需要它,但它会删除重复的值
    foreach($key=>$value){
    if(在数组中($value,$valid)){
    $class=true;
    }否则{
    取消设置($post[$key])#删除不正确的值,这也可能不是必需的,但会删除不需要的项。
    }
    }
    if(isset($class)){
    $class='class=“class.”内爆('class',$post)。“;
    }
    }#非数组类别是否还需要其他?