Jump to content

(PHP Button) So simple yet so complicated?!? Please help


Saves

Recommended Posts

Hello everyone, I am currently coding what I thought would be a simple PHP button that would alternate each time you click it to provide a different action. I've spent almost 2 hours trying to figure this out but I'm stumped at this point. I need your help.. Here is what I have so far:

 

the PHP:

<?php
session_start();


$pause = 1;
$btnname = "Pause";
$btntype = "pause";


if (isset($_POST['button'])) {

if (isset($pause)) {
unset($pause, $btnname, $btntype);
$play = 1;
$btnname = "Play";
$btntype = "play"; 

} else if (isset($play)) {
unset($play, $btnname, $btntype);
$pause = 1;
$btnname = "Pause"; 
$btntype = "pause"; 

}

?>

The HTML:

<a href="#" onclick="var myPlayer = document.getElementById('playerid'); myPlayer.<?php echo $btntype; ?>Video();"><input name="button" type="submit" id="button" value="<?php echo $btnname; ?>" /></a>

The Goal is to simple create a button where it will alternate between a "Play" and "Pause" command.

 


<?PHP
  session_start();
 
  $pause = 1;
  $btnname = "Pause";
  $btntype = "pause";

  if($_SERVER['REQUEST_METHOD'] == 'POST') {
//### Debug Data
    //echo '<pre>';
    //print_r($_POST);
    //echo '</pre>';
    
    $postedButton = isset($_POST['button']) ? strtolower($_POST['button']) : '' ;
    
    if($postedButton == 'pause') {
      $play = 1;
      $btnname = "Play";
      $btntype = "play";
    } else if($postedButton == 'play') {
      $pause = 1;
      $btnname = "Pause";
      $btntype = "pause";
    }  
  }

?>
<form method="POST">

  <a href="#" onclick="var myPlayer = document.getElementById('playerid'); myPlayer.<?php echo $btntype; ?>Video();">
    <input name="button" type="submit" id="button" value="<?php echo $btnname; ?>" />
  </a>
 
</form>
<?PHP
  session_start();
 
  $pause = 1;
  $btnname = "Pause";
  $btntype = "pause";

  if($_SERVER['REQUEST_METHOD'] == 'POST') {
    //### Debug Data
    //echo '<pre>';
    //print_r($_POST);
    //echo '</pre>';
    
    $postedButton = isset($_POST['button']) ? strtolower($_POST['button']) : '' ;
    
    if($postedButton == 'pause') {
      $play = 1;
      $btnname = "Play";
      $btntype = "play";
    } else if($postedButton == 'play') {
      $pause = 1;
      $btnname = "Pause";
      $btntype = "pause";
    }  
  }

?>
<form method="POST">

  <a href="#" onclick="var myPlayer = document.getElementById('playerid'); myPlayer.<?php echo $btntype; ?>Video();">
    <input name="button" type="submit" id="button" value="<?php echo $btnname; ?>" />
  </a>
 
</form>

 

Hey I really appreciate your help! I tried imputing this code and it didn't work. The button didn't even have a Value in it and when I clicked it, it would just reload the page and the song would play again from the beginning.

I did exactly what your previous code looked like it was attempting to do.

 

It seems as though you're trying to change a client side action with a server side output.

You need to look into a javascript version of the above code.

 

 

<script type="text/javascript">
  function performAction(){
    var button   = document.getElementById('actionButton');
    var myPlayer = document.getElementById('playerid');
    
    if(button.value.toLowerCase() == 'pause') {
      button.value = 'Play';
      myPlayer.pauseVideo();
    } else {
      button.value = 'Pause';
      myPlayer.playVideo();
    }    
  }
</script>


<input type="button" id="actionButton" onClick="performAction();" value="Pause">

 

I did exactly what your previous code looked like it was attempting to do.

 

It seems as though you're trying to change a client side action with a server side output.

You need to look into a javascript version of the above code.

<script type="text/javascript">
  function performAction(){
    var button   = document.getElementById('actionButton');
    var myPlayer = document.getElementById('playerid');
    
    if(button.value.toLowerCase() == 'pause') {
      button.value = 'Play';
      myPlayer.pauseVideo();
    } else {
      button.value = 'Pause';
      myPlayer.playVideo();
    }    
  }
</script>


<input type="button" id="actionButton" onClick="performAction();" value="Pause">

 

Oh my god you are a freaking genius! I cannot express the amount of gratitude and appreciation I have for you right now. I hope you are given everything you want in life!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.