duagfgfn1981 2019-07-11 13:04
浏览 70
已采纳

从滚动条中选择如何检测选项或在表单提交的文本栏中输入值?

I am working to perform if else condition on form submission (POST Method) by detecting whether (the scroll option projectcode is selected AND the date is entered or not) OR (the value modifieddate is entered or not).

Based on the detection i am executing my if else conditions but things are not working.

I have a form inside in file dashboard.php

<form action='dashboardentry.php' method='post'>

    <label>Project Code: </label>
    <select name='projectcode'>
        <option value=''>Select...</option>
        <option value='COP-INT'>COP-INT</option>
    </select>

    <label>Date: </label>
    <input type='date' name='date'>

    <label>OR</label>

    <label>Modified Date: </label>

    <input type='text' name='modifieddate'>

    <button type='submit' name='delete'>Delete Entry</button>

</form>

I basically want to check whether to perform delete operation via project code and date variable value or via modified date in my database (has entries of hours spent) and for this i done below things.

In the file dashboardentry.php

<?php

if($_SERVER['REQUEST_METHOD'] === 'POST'){

    if(isset($_POST['projectcode']) AND isset($_POST['date'])){

    }elseif(isset($_POST['modifieddate'])){

    }else{

        echo "Please Enter either Project Code or Modified Date to delete Entry";

    }
?>

But my problem is that this if else is not working properly as per my expectation. plz help.

  • 写回答

1条回答 默认 最新

  • duananyantan04633 2019-07-11 13:14
    关注

    maybe check if values aren't not empty like this :

    <?php
    
    if($_SERVER['REQUEST_METHOD'] === 'POST'){
    
        if( isset($_POST['projectcode']) &&
            !empty($_POST['projectcode']) &&
            isset($_POST['date']) &&
            !empty($_POST['date'])){
    
        } else if(isset($_POST['modifieddate']) && !empty($_POST['modifieddate'])){
    
        } else{
    
        echo "Please Enter either Project Code or Modified Date to delete Entry";
    
    }
    
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?