Page 1 of 1

[solved] confirm and output

Posted: 10 Mar 2015 14:47
by lian00
Hello,
I want to use the confirm() function to ask if I want to continue to run an script or stop it but I'm a little lost. When I put only msg confirm("Ok?"); I've got two messages, the second with the value of the choice. And how to use this value to make a test ?
Thanks for any help.

Re: confirm and output

Posted: 10 Mar 2015 14:52
by highend

Code: Select all

    $result = confirm("Continue script?", , , 4);
    if ($result) {
        echo "You clicked the yes button";
    } else {
        echo "You clicked the no button";
    }

Re: confirm and output

Posted: 10 Mar 2015 14:56
by bdeshi
Maybe a leeettle bit more explanation would help.

Confirm dialogs by default have Yes and Cancel buttons. When your press Yes, confirm() returns 1, else it returns 0. More buttons can be added, and each button has different integer return values.
if ($return) is true as long as $return is not empty nor 0, meaning its true as long as Cancel/No was not pressed

Re: confirm and output

Posted: 10 Mar 2015 15:04
by lian00
So

Code: Select all

$result = confirm("Continue script?", , , 4);
will show the message AND save the value in $result automatically ?

Re: confirm and output

Posted: 10 Mar 2015 15:06
by bdeshi
yes

Re: confirm and output

Posted: 10 Mar 2015 15:07
by highend
will show the message AND save the value in $result automatically ?
Of course...

Re: confirm and output

Posted: 10 Mar 2015 15:17
by lian00
highend wrote:
will show the message AND save the value in $result automatically ?
Of course...
Powerful ! :!: Thanks a lot.

Re: [solved] confirm and output

Posted: 10 Mar 2015 15:24
by lian00
Complement: I found the end function.
So

Code: Select all

 end confirm ("Continue script ?") == 1; 
    blablabla (script to continue);

Re: [solved] confirm and output

Posted: 10 Mar 2015 15:27
by bdeshi
Actually that will end the script if you press OK.
You should use

Code: Select all

 end confirm ("Continue script ?") != 1; //end if anything but OK pressed
    blablabla (script to continue);
end stops running the script if the condition is true. When the condition is confirm ("Continue script ?") == 1; it really means: end if confirm() returns 1 (which occurs when pressing OK/Yes)

Re: [solved] confirm and output

Posted: 10 Mar 2015 15:52
by lian00
You are right - I made the test :-)