Jump to content

selected entry will not get selected


rizzler

Recommended Posts

I have this loop on a shorturl website i own that selects domains from my website and lists them in a dropdown list where users can select one domain to use as url shortener.

The problem is that when a users selects and entry from the dropdown list this created only the [[[main_url]]] entry from the database table bellow can be used. When someone selectes "coolartistname.site.com the submit button cannot be pressed. in other words it's not adding the SELECTED attribute other than the [[[main_url]]] domain.

Can anyone see on the code bellow why this would happen?


When i echo $shortUrlDomains it's just saying "Array" and $_REQUEST['shortUrlDomain'] shows nothing.

**Index.php**

    // get base urls
    $shortUrlDomains = getShortUrlDomains();
    
        <?php
        foreach ($shortUrlDomains AS $k => $shortUrlDomain)
        {
        
            // active domains only
            if (($shortUrlDomain['premium_only'] !== '1') && ($shortUrlDomain['premium_only'] !== $Auth->id))
            {
                continue;
            }
        
            echo '<option value="' . (int)$k . '"';
        
            if (isset($_REQUEST['shortUrlDomain']))
            {
                if ($k == (int)$_REQUEST['shortUrlDomain'])
                {
                    echo 'SELECTED';
                }
            }
        
            echo '>';
        
            echo $shortUrlDomain['domain'];
        
            if ($disabled == true)
            {
                echo ' (' . safeOutputToScreen(t('unavailable', 'unavailable')) . ')';
            }
        
            '</option>';
        }
        echo '</optgroup>';
        ?>

FUNCTIONS.PHP

    function getShortUrlDomains()
    {
        // if we already have it cached
        if(defined('_SETTINGS_SHORT_URL_DOMAINS'))
        {
            return unserialize(_SETTINGS_SHORT_URL_DOMAINS);
        }
        
        // get connection
        $db  = Database::getDatabase(true);
        
        // load from database
        $domains = $db->getRows("SELECT id, domain, premium_only, status FROM url_domain ORDER BY premium_only ASC, id ASC");
        
        // organise and replace site url
        $rs = array();
        foreach($domains AS $domain)
        {
            if($domain['domain'] == '[[[main_url]]]')
            {
                $domain['domain'] = _CONFIG_SITE_FULL_URL;
            }
            $rs[$domain{'id'}] = $domain;
        }

**MYSQL DATABASE**

    url_domain (id, domain, premium_only, status, date_created, owner) VALUES
    (1, '[[[main_url]]]', 0, 'enabled', '2019-03-02 08:13:00', 1) 
    (14, 'coolartistname.site.com', 6, 'enabled', '2020-04-18 19:21:59', 6);

 

Link to comment
Share on other sites

$_REQUEST is discouraged, not deprecated, due to the way that it may or may not contain certain values depending on php.ini settings. Best practice is to get the value specifically from the query string ($_GET) or submitted form data ($_POST).

But unless you have a weird setup, $_REQUEST should contain both of $_GET and $_POST (if not more). If there is no "shortUrlDomain" key in it then that probably means there was no value being passed, so the first step should be looking at where the value is supposedly being passed to the PHP script.

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.