简体   繁体   中英

Change PHP Form row value if another row value is not 0 on submit

I have a ticketing system and I have a Ticket Edit form. The rows which are important are these : Status Which have these options: value 0 = Open value 1 = close value 2 = Checking value 3 = deleted . And another row is Staff Which contains the Staffs of my website which answers the questions. so the Staff row have these options: value 0 = empty and other values are my Staffs User ID. What I Want to do is when the staff value row changed from 0 which is none to anything else , The Status Value automatically change from Open to Checking Only When the Ticket is Open ( value = 0 ). I've tried this JQuery code:

<script>
    $("[name='call_staff']").change( function() {
        if( (this.value) != 0) {
            $("[name='call_status']").val(2);
        } else {
            $("[name='call_status']").val(0);
        }
    }).change();
</script>

But the problem is when Staff want to change the Status From Checking to Close , After Submit , the status value is still Checking . I want a PHP code for this thing.

Do this by using $.submit() handler on your form.

Could look somehow like this:

jQuery(document).ready(function($){
    $('#YOUR-FORM-ID').submit(function(){
        if (parseInt($('[name="call_staff"]').val()) != 0 && parseInt($('[name="call_status"]').val()) == 0) // we force both values to be integer and do the check
        {
            // now the UID is not 0
            $('[name="call_status"]').val(2);
        }
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM