confirm as in javacript confirm

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
daffy
Forum Newbie
Posts: 7
Joined: Wed Aug 19, 2009 7:29 am

confirm as in javacript confirm

Post by daffy »

I am a novice writing a web-site and at one point I am faced with offering my users a choice of 'confirm' or 'cancel'.
Confirm takes them straight to homepage and cancel required a function before going to home page.
How to do this worried me until I cam across javascript confirm. BUT it is ugly ! I cannot alter it with css.
I hunted on the internet and found various complex, and beautiful java implementations but I want something simple !
SO this is what I did (in Joomla) is it safe ? and is it reliable? As a novice I have no idea so please help.
I made a simple form with two submit buttons

Code: Select all

echo "<form id=\"myform\" action = \"index.php?option=com_content&view=article&id=38&Itemid=44\" method = \"post\" target= \"self\" style = \"margin: 0px;\">";
 
echo "<input type = \"submit\" id=\"butnA\" name = \"butnA\" value = \"A\" >";
echo "<input type = \"submit\" id=\"butnB\" name = \"butnB\" value = \"B\" >";
 
echo "</form>";
 
This form action goes to the home page
The at the top of the home page I put inside a php call

Code: Select all

 
  $name1 = "butnA";
  $name2 = "butnB";
   $aresult = JRequest::getVar($name1);
   echo "<p>A result is $aresult</p>";
   if ($aresult){   functionA();}
   else
   {
   $bresult = JRequest::getVar($name2);
   echo "<p> B result is $bresult</p>";
   if ($bresult){ functionB();}
   else{ //carry on as normal to display the home page
 
It seems to work if I look at the echos put there for that purpose...but is it reliable ?
Any advice or help welcome.
Or is there a better way to do it ?

--
Dave
User avatar
mrvijayakumar
Forum Commoner
Posts: 58
Joined: Tue Aug 18, 2009 12:39 am
Location: Chennai city, India
Contact:

Re: confirm as in javacript confirm

Post by mrvijayakumar »

Hi,
I hope i am redirecting u to correct path, If u OK with below coding means u can use it, otherwise omit it, Reply me for any case.

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Javascript Confirm Redirect</title>
<script language="javascript" type="text/javascript">
function confirmredirect()
{
    if(window.confirm("Do you want to redirect? Press OK to continue or press CANCEL to stay in same page"))
    {   
    window.location="index.php?option=com_content&view=article&id=38&Itemid=44";
    }
}
</script>
</head>
<body>
<form action="" method="post"><input name="clickbut" type="button" value="Click this button" onclick="return confirmredirect();" /></form>
</body>
</html>
daffy
Forum Newbie
Posts: 7
Joined: Wed Aug 19, 2009 7:29 am

Re: confirm as in javacript confirm

Post by daffy »

Thanks vijay,
You are offering me a conditional 'redirect' I understand that, but I have two cases 'OK' the form needs to go to the home page and 'CANCEL' in which case there needs to be some operations before going to the home page.
Now as I understand it

Nothing happens in a web-page without a button press by the client, So if he is redirected to a php script or another page how can he get from there to the home page without another button?

The poor man has had too many buttons to press already.
I have looked at bits of script to trigger an apparent button press but that is more complex.

But thanks for the prompt reply.
Dave
User avatar
mrvijayakumar
Forum Commoner
Posts: 58
Joined: Tue Aug 18, 2009 12:39 am
Location: Chennai city, India
Contact:

Re: confirm as in javacript confirm

Post by mrvijayakumar »

Hi thanks,

Just modify this JavaScript function, I hope, i given correct result. Reply me please.

Code: Select all

function confirmredirect()
{
    if(window.confirm("Do you want to redirect? Press OK to continue or press CANCEL to stay in same page"))
    {   
    window.location="index.php?option=com_content&view=article&id=38&Itemid=44";
    } else {
             window.location="RedirectToSomeFile.php";
}
}
Post Reply