Jump to content

Submitting the Form


Go to solution Solved by Barand,

Recommended Posts

So I'm trying to submit the name of a teamspeak 3 channel and the one word channels work fine with using $_POST['channel'] but if the string is two words (separated by a space) then it only uses the first word of the string
 
Form.php: 
 <form name="kick" method="POST" action="kick.php">
            <select name="channel" id="channel">
                <option value="default" name="default" selected>Choose One</option> 
                <?php
                require_once("Teamspeak3/libraries/TeamSpeak3/TeamSpeak3.php");
                $ts3_VirtualServer = TeamSpeak3::factory("serverquery://<username redacted>:<password redacted>
@localhost:10011/?server_port=9987");
                foreach ($ts3_VirtualServer->channelList() as $ts3_Channel) {
                    echo "<option value=" . $ts3_Channel["channel_name"] . ">" . $ts3_Channel["channel_name"] . "</option>";
                }
                ?>
            </select>
            <input type="submit" name="Kick Players"/>        
</form>
 
Kick.php:
<?php session_start();
define('MYSITE', $_SERVER['SERVER_NAME'] . ":8000"); //define what our site is.
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if ($_POST['channel'] == "default") {
        header('Location: http://' . MYSITE . '/panel_error.php?reason=default');
        exit();
    } else {
        $clients = array();
        require_once("Teamspeak3/libraries/TeamSpeak3/TeamSpeak3.php");
                $ts3_VirtualServer = TeamSpeak3::factory("serverquery://<username redacted>:<password redacted>
@localhost:10011/?server_port=9987");
        $channel = $ts3_VirtualServer->channelGetByName($_POST['channel']);
        foreach($ts3_VirtualServer->clientList() as $client) {
            if($client['cid'] == $channel->getId()) {
                $clients[$client->getId()] = $client;
            }
        }
        if(empty($clients)) {
             header('Location: http://' . MYSITE . '/panel_error.php?reason=noclients'); 
             exit();
        }
        $ts3_VirtualServer->clientKick($clients, TeamSpeak3::KICK_SERVER, "You have been kicked from the server!");
        header('Location: http://' . MYSITE . '/panel.php'); 
        exit();
    }
}

EXAMPLE OF PROBLEM: 

In the drop down list I choose 'Admin Room'.
I submit and when I run:

$channel = $ts3_VirtualServer->channelGetByName($_POST['channel']);

it runs as:
 

 $channel = $ts3_VirtualServer->channelGetByName('Admin');

instead of: 
 

 $channel = $ts3_VirtualServer->channelGetByName('Admin Room');

THE ERROR:
 

C:\path\to\project\kick.php(11): TeamSpeak3_Node_Server->channelGetByName('Admin'); //results in below

Fatal error: Uncaught exception 'TeamSpeak3_Adapter_ServerQuery_Exception' with message 'invalid channelID'
Edited by FatesCall
Link to comment
https://forums.phpfreaks.com/topic/296708-submitting-the-form/
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.