Forum Moderators: coopster

Message Too Old, No Replies

Submit button to count

count

         

JuicyScript

10:27 am on Jan 16, 2010 (gmt 0)

10+ Year Member



Can some one help me with this?I want different buttons to appear on increment of a count.

<? $sql="SELECT * FROM members WHERE login='".md5($_POST['login'])."' AND passwd='".md5($_POST['password'])."'";
$qry=mysql_query($sql);
$result=mysql_fetch_array($qry);

if($result['count']>=3) {
echo "<input name="Submit" type="submit" value="Finish" />";

}else{

<input type="button" name="post" class="FormInput2" value="Submit" onclick="popup(); "/>
}
</p>
?>

rocknbil

9:01 pm on Jan 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try something like this, untested so may have syntax errors. Don't use button types, they won't work without Javascript. Note the added variables to insure users get content.

<?php
$sql="SELECT * FROM members WHERE login='".md5($_POST['login']).
"' AND passwd='".md5($_POST['password'])."'";
$qry=mysql_query($sql);
$result=mysql_fetch_array($qry);
$form ='<form action="some-script.php">';
if($result['count']>=3) {
$form .= '<input name="Submit" type="submit" value="Finish">';
}
else{
for ($i=0;$i<=3;$i++) {
// whatever you pass into popup() for the 3 states, use the value of
// $buttonname in some-script.php to do whatever you do in popup(),
// for example, to parse $buttonname to return $this_url
$buttonname = 'button_' . $i;
$this_url = 'whatever_' . $i . '.html';
$form .= '
<input type="hidden" name="' . $buttonname . '" value="' . $i . '">
<input type="submit" name="' . $buttonname .
'" class="FormInput2" value="Submit" onclick="return popup(\'' . $this_url . '\');">';
}
}
$form .= '</form>
<script type="text/javascript">
function popup(url) {
var day = new Date();
var id = day.getTime();
var params="width=500,height=500,scrollbars,resizable";
var win = open (url,id,params);
return false;
}
</script>
';
echo $form;
?>

The return false is important, it's what stops the form from submitting on the button click.

This still has a problem, though, if the user presses enter, only the first button in the source code will be triggered (or none at all.) Generally you put the event handlers on the form, not the button, to handle this case, so you'll need somethign on the form to manage it, like

$form ='<form action="some-script.php" onsubmit="return some_function(this);">';

But not knowing the full scope, not sure what help to offer there . . .

rocknbil

9:08 pm on Jan 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<facepalm>

Or, you are just saying . . . this limits login attempts? If so,


<?php
$sql="SELECT * FROM members WHERE login='".
md5($_POST['login'])."' AND passwd='".md5($_POST['password'])."'";
$qry=mysql_query($sql);
$result=mysql_fetch_array($qry);
$form ='<form action="some-script.php">';
if($result['count']>=3) {
$form .= '<input name="Submit" type="submit" value="Finish">';
}
else{
$form .=
<input type="submit" name="post" class="FormInput2" value="' .
Login attempt number ' . $result['count'] . '" onclick="return popup();">';
}
}
$form .= '</form>';
echo $form;
?>

JuicyScript

1:04 am on Jan 17, 2010 (gmt 0)

10+ Year Member



Thanks mehn..it worked...But how can i refresh the main page i clicked on to execute the pop up window by clicking on a button on the pop up window

rocknbil

4:50 am on Jan 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The main window is "window.opener."

So from the pop up window, you can access any elements or functions in the window.opener like so:

if (window.opener) {
window.opener.document.location='http://www.example.com';
window.close();
}

The above would direct the parent to example.com then close the pop up.

Curious, what were you trying to do?