[solved] confirm and output

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
lian00
Posts: 429
Joined: 09 Jul 2014 17:12

[solved] confirm and output

Post 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.
Last edited by lian00 on 10 Mar 2015 15:17, edited 1 time in total.
Windows 10 64 bits

highend
Posts: 14942
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: confirm and output

Post 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";
    }
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: confirm and output

Post 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
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

lian00
Posts: 429
Joined: 09 Jul 2014 17:12

Re: confirm and output

Post by lian00 »

So

Code: Select all

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

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: confirm and output

Post by bdeshi »

yes
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

highend
Posts: 14942
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: confirm and output

Post by highend »

will show the message AND save the value in $result automatically ?
Of course...
One of my scripts helped you out? Please donate via Paypal

lian00
Posts: 429
Joined: 09 Jul 2014 17:12

Re: confirm and output

Post by lian00 »

highend wrote:
will show the message AND save the value in $result automatically ?
Of course...
Powerful ! :!: Thanks a lot.
Windows 10 64 bits

lian00
Posts: 429
Joined: 09 Jul 2014 17:12

Re: [solved] confirm and output

Post by lian00 »

Complement: I found the end function.
So

Code: Select all

 end confirm ("Continue script ?") == 1; 
    blablabla (script to continue);
Windows 10 64 bits

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: [solved] confirm and output

Post 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)
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

lian00
Posts: 429
Joined: 09 Jul 2014 17:12

Re: [solved] confirm and output

Post by lian00 »

You are right - I made the test :-)
Windows 10 64 bits

Post Reply