简体   繁体   中英

Check if text is input in text box and if radio buttons are selected + alert and direct to a page

I want to have checked if the textboxes are empty and if the radio buttons are selected. If they are not all OK, I want to get a pop-up message saying that they need to do everything and then redirect to the begin page. The code is written in Dutch. I need a pop-up version for the echo, so if they clicked on the pop-up they get directed to the Enquete.php .

session_start();
if(isset($_POST["versturen"])){
    if (empty($Jurylid) or empty($Organisatie) or empty($Firma) or empty($Standnummer) or empty($Aanmelden) or empty($Ontvangst) or empty($Contact) or empty($Gesprek) or empty($Luisteren) or empty($ProductKennis) or empty($HandelKennis) or empty($Onderhandelen) or empty($TaalGebruik) or empty($Voorkomen)){ 
    echo("Make sure you did everything!");
    header('location:Enquete.php');
    }

You will be probably needing a JS version then..

Do this way

session_start();
if(isset($_POST["versturen"])){
    if (empty($Jurylid) or empty($Organisatie) or empty($Firma) or empty($Standnummer) or empty($Aanmelden) or empty($Ontvangst) or empty($Contact) or empty($Gesprek) or empty($Luisteren) or empty($ProductKennis) or empty($HandelKennis) or empty($Onderhandelen) or empty($TaalGebruik) or empty($Voorkomen)){
        echo "<script>alert('Make sure you did everything!')</script>"; //<---- A JS Alert
        echo "<script>document.location.href='Enquete.php'</script>"; // <--- A JS Redirect
    }

I think it would be easier (and more nice for the user) if you work that with javascript (jQuery could be quite useful in this case). Is there any chance you can do that in js?

Imagine that your input type text is named "textInput", you could add the listener:

$('input[name=textInput]').change(function(){});

But also you could check the value of the input before submit:

if ($('input[name=textInput]').val() == '') {
   console.log("It's empty")<
}

It's pretty similar with the radio button. Then you could automatically trigger an alert with out reload the page.

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