Jump to content

conformation box popup in php


richiec

Recommended Posts

Im trying to get a conformation pop up in php when someone presses a button but this is the first time ive ever tried to add something like this with mixing javascript and php together..

 

Right now it echos "You canceled your bid." for both yes and no so any ideas of how to fix this would be appreciated! The code is below..

 

<SCRIPT language="JavaScript">
<!--
function go_there()
{
var where_to= confirm("Do you really want to?");
if (where_to== true)
{
   <?php $confirmbid = "yes"; ?>
}
else
{
  <?php $confirmbid = "no"; ?>
  }
}
//-->
</SCRIPT>

 

and then the form part

 

echo "<input type=\"submit\" name=\"auctionbid\" value=\"BID\" onClick=\"go_there()\">";

 

and then the follow through after its pressed..

 

if ($confirmbid == "no"){
echo "You canceled your bid.";
}
else {
///do query
}

 

Thanks

 

~Rich

Link to comment
Share on other sites

javascript and PHP can not talk to each other in that way. Since one is parsed server side and the other client side, the only places these two can talk is through post and get variables ( I think, someone correct me if I am wrong)

 

Also, you cant change variables in a PHP page once it has been loaded without reloading the page. What you want to do can be done with PHP fairly easily if you submit the form, but using Javascript and PHP in the way you want is impossible I'm afraid (as far as I know. again I could be wrong)

Link to comment
Share on other sites

ok so pressing "yes" could just reload to a ?confirm=yes and pressing "no" would just reload back to normal page and then it would be able to get it from there i guess

 

Or not ^^ lol it loses the variables it gets when clicking bid when java changes the page -_- i hate javascript ha

 

Isnt there any way to do a confirmation box in just php oO

Link to comment
Share on other sites

ok so pressing "yes" could just reload to a ?confirm=yes and pressing "no" would just reload back to normal page and then it would be able to get it from there i guess

 

Or not ^^ lol it loses the variables it gets when clicking bid when java changes the page -_- i hate javascript ha

 

Isnt there any way to do a confirmation box in just php oO

 

no you're right. do this with javascript:

 

window.location = 'http://www.yoursite.com/index.php?confirmed=yes'

 

and on the index.php get the confirmed from this:

$_GET['confirmed']

Link to comment
Share on other sites

well, Im not versed to well in Javascript (I know a good amount of it, but your specific problem would take a little bit of research on my part to answer)

 

can you do a confirmation type box in PHP? of course, but it won't really be as dynamic as in javascript (like you wont be able to make a pop-up box really).

 

you could just make a form with two submit buttons, one called yes, and one called no, as so

<input type=\"submit\" name=\"yes\" value=\"BID\" >";
<input type=\"submit\" name=olue=\"BID\">";

 

and on your php page do something like

if (isset($_POST['yes'])){
//blah blah
}
else if ($_isset($_POST['no'])){
//blah blah
}
else {
echo "YOU AINT CLICK NUTHIN"
exit();
}

 

is that what you were looking for? I hope that helps

Link to comment
Share on other sites

ok so pressing "yes" could just reload to a ?confirm=yes and pressing "no" would just reload back to normal page and then it would be able to get it from there i guess

 

Or not ^^ lol it loses the variables it gets when clicking bid when java changes the page -_- i hate javascript ha

 

Isnt there any way to do a confirmation box in just php oO

 

no you're right. do this with javascript:

 

window.location = 'http://www.yoursite.com/index.php?confirmed=yes'

 

and on the index.php get the confirmed from this:

$_GET['confirmed']

 

Or do that lol

Link to comment
Share on other sites

ok so pressing "yes" could just reload to a ?confirm=yes and pressing "no" would just reload back to normal page and then it would be able to get it from there i guess

 

Or not ^^ lol it loses the variables it gets when clicking bid when java changes the page -_- i hate javascript ha

 

Isnt there any way to do a confirmation box in just php oO

 

no you're right. do this with javascript:

 

window.location = 'http://www.yoursite.com/index.php?confirmed=yes'

 

and on the index.php get the confirmed from this:

$_GET['confirmed']

 

Yeah thats how i just had it set up after reading his reply but it lost the php post variables for clicking the button before java reloads the page and didnt go through

Link to comment
Share on other sites

well, Im not versed to well in Javascript (I know a good amount of it, but your specific problem would take a little bit of research on my part to answer)

 

can you do a confirmation type box in PHP? of course, but it won't really be as dynamic as in javascript (like you wont be able to make a pop-up box really).

 

you could just make a form with two submit buttons, one called yes, and one called no, as so

<input type=\"submit\" name=\"yes\" value=\"BID\" >";
<input type=\"submit\" name=olue=\"BID\">";

 

and on your php page do something like

if (isset($_POST['yes'])){
//blah blah
}
else if ($_isset($_POST['no'])){
//blah blah
}
else {
echo "YOU AINT CLICK NUTHIN"
exit();
}

 

is that what you were looking for? I hope that helps

 

What i am doing is making a kind of auction website for a game i play my guild members earn points for doing different things and then every week they bid against eachother with the points they have earned on the items we have won..

 

The auction works fine its just some noobs kept messing up there bids so i just wanted to add a conformation box to try and cut down on the amount of people who mess up and bid on the wrong thing..

 

So unfortunetly what you posted isnt what im looking for, unless i misunderstood what you were saying to do..

Link to comment
Share on other sites

oh, yeah I misunderstood what you were trying to do.

 

window.location = 'http://www.yoursite.com/index.php?confirmed=yes'

should work just fine to be honest. Can you post the javascript you are using with your confirmation box.

 

by the way, dont EVER call javascript java or vice versa. Javascript, and Java are two completely different programming languages, and calling them the same thing can get you yelled at lol.

Link to comment
Share on other sites

oh, yeah I misunderstood what you were trying to do.

 

window.location = 'http://www.yoursite.com/index.php?confirmed=yes'

should work just fine to be honest. Can you post the javascript you are using with your confirmation box.

 

by the way, dont EVER call javascript java or vice versa. Javascript, and Java are two completely different programming languages, and calling them the same thing can get you yelled at lol.

 

 

This is the java"script" hehe :P

 

<SCRIPT language="JavaScript">
<!--
function go_there()
{
var where_to= confirm("Do you really want to bid?");
if (where_to== true)
{
   window.location="?auction=view&confirm=yes";
}
else
{
  window.location="?auctions=view";

  }
}
//-->
</SCRIPT>

 

get part

 

if ($_REQUEST["auctionbid"] != NULL){
////
$confirmbid = $_GET['confirm'];

if ($confirmbid == ""){
echo "";
}

else {
blah blah
}

Link to comment
Share on other sites

hmm that looks like it SHOULD work... instead of what you have try

function go_there()
{
var where_to= confirm("Do you really want to bid?");
if (where_to)//since this already has a bool value in it there is no reason to check whether or not the value is true
{
   window.location="?auction=view&confirm=yes";
}
else
{
  window.location="?auctions=view";

  }
}

Link to comment
Share on other sites

OOOH i see the problem (I think) When you do window location, if you dont add an absolute URL (IE http://www.website.com) then it just appends the current URL with what you are going to. try instead of what you have, putting the absolute url, and see if there is a problem.

 

I may be completely wrong though. As I said, my knowledge of javascript is not somewhat lacking (this is the PHP forums ya know!)

 

hope that helps!

Link to comment
Share on other sites

Ive tried it with both full links and the short one :( didnt do anything that was one of the first things i tested but still no change.

 

Thanks alot for the help though mikesta707 <3 its like 5am here now though so im going to head to bed and check back tomorrow and see if anyones come up with anything

Link to comment
Share on other sites

i tried the below code on my server and its working perfectly fine.

 

post ALL your code that has anything to do with this project. Including where you call the function, etc.

<script type="text/javascript">
function go_there()
{
var where_to= confirm("Do you really want to bid?");
if (where_to)
{
   window.location="http://www.google.com/?auction=view&confirm=yes";
}
else
{
  window.location="http://www.google.com/?auctions=view&confirm=no";

  }
}
</script>

<a href="#" onClick="go_there()">test</a>

Link to comment
Share on other sites

Alright as i said before what im trying to do is have a kind of auction set up (which is working fine) however i would like to add a conformation box whenever they bid on an item due to some noobs not paying attention when bidding.

 

Here is the javascript

 

<SCRIPT language="JavaScript">

function go_there()
{
var where_to = confirm("Only click ok if you are sure its the item you want to bid on!");
if (where_to == true)
{
   window.location = "?confirm=yes";
}
else
{
  window.location = "?auctions=view";

  }
}

</SCRIPT>

 

It then calls the function when bidding

 

<form name=\"bid\" method=\"post\" action=\"\" target=\"_self\">

<center><input type=\"text\" name=\"bidnumber\" value=\"$newbid\" size=\"3\" maxlength=\"3\" onKeyPress=\"return numbersonly(this, event)\"> <input type=\"submit\" name=\"auctionbid\" value=\"BID\" onClick=\"go_there()\"><input type=\"hidden\" name=\"auctionid\" value=\"$idid\"></center>

</form>

 

Now that form needs to get a few things (if they press ok on the conformation box) for example it needs to get the amount that was bidded and the auctionid

 

If the person presses ok on the conformation box it then does an sql queery to update the things if they press cancel obviously it doesnt..

 

This is the sql queery for the example

 

if ($_REQUEST["auctionbid"] != NULL){
////
$confirmbid = $_GET['confirm'];

if ($confirmbid == "yes"){
$nick = $_SESSION["wishlistusername"];
$bidnumber = $_POST['bidnumber'];
$auctionid = $_POST['auctionid'];


$query="SELECT * FROM ` blah blah blah.... }

else {

do nothing since they pressed cancel }

 

 

I really hope someone can help =\ i know its possible to do i just dont know how to do it correctly...

Link to comment
Share on other sites

you need to define action in the form tag.

 

then you would do something similar to this:

function go_there()
{
var where_to = confirm("Only click ok if you are sure its the item you want to bid on!");
if (where_to == true)
{
   document.bid.submit();
}
else
{
//do nothing

  }
}

Link to comment
Share on other sites

Why not do something like this:

 

something.html

<!-- HTML here -->

<form action="/path/to/something.php" method="post" name="auction" onsubmit="return validate();">
     <input type="radio" name="item" value="ball" /> Ball
     <input type="radio" name="item" value="yoyo" /> Yo-yo
     <input type="submit" name="submit" value="Submit" /> Submit
</form>

<!-- more HTML here -->

<script type="text/javascript">
function validate () {
     var options = document.forms.auction.item.value;
     for (var e = options.length; --e > -1; ) {
          if (options[e].checked) {
               return confirm("Are you sure you want to select " + options[e].value);
          }
     }
     return false;
}
</script>

 

something.php

<?php

// check your PHP version to make sure filter_input works.
// if not, use the superglobal
$option = filter_input(INPUT_POST, 'item');
// do something
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.