Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6734177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:51:28+00:00 2026-05-26T10:51:28+00:00

I made a page where users can input a Hex Code for different colors

  • 0

I made a page where users can input a Hex Code for different colors they want to change on their page. It all works fine, but I would like to make it so if the box the user is inputting to is empty, then display the default CSS. Otherwise, display a custom one.

I’ll use an example:

The users choice gets sent to a form validation:

$this->form_validation->set_rules('channelNameColor',
                    lang('user_themes_channel_name_color'),
                    'trim|strip_tags|xss_clean|min_length[6]|max_length[6]');

Then it eventually gets passed to a file where it can be used in CSS:

It is declared here:

$channelNameColor = $theme['channelNameColor'];

Then down below all those declarations it gets put in as CSS:

.channelNameBar h1{
font-size:20px;
color:#<?=$channelNameColor?>;
float: left;
}

I would like to do something like this:

<?php
if (empty($channelNameColor)){
     echo ".channelNameBar h1{";
     echo "font-size:20px;";
     echo "color:#FFFFFF;";
     echo "float: left;";
     echo "}";
}
else
 {
     echo ".channelNameBar h1{";
     echo "font-size:20px;";
     echo "color:#$channelNameColor;";
     echo "float: left;";
     echo "}";
 }
?>

But it is not recognizing $channelNameColor in: if (empty($channelNameColor)){

Why is it not recognizing it there, but it recognizes it fine when I use it in the css?
Sorry if this is a very simple question to answer, I’m pretty new to PHP

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:51:28+00:00Added an answer on May 26, 2026 at 10:51 am

    Generally it would make more sense not to declare channelNameColor at all if the user input is empty. You can do this in your validation!

    Then later on you can use isset() instead of empty(), which is a bit more reliable after you did your validation!

    Also make sure that you include your else-statement in curly brackets, otherwise it will output it anyway!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I`v made my webpart that works well (I can add it to page and
i made an HTML page with all widths and heights as percentage that's primary
I have to update the users based on input value.. here is my code..
What I want is a function I can run on user input that will
There is a one section of orders page where users can add new fields
I'm trying to build a Drupal site in which users can input records containing
I have made a web application that uses master page for Login & Logout
I made a page, 3 cols, tableless and css formated (as it should be).
I have to made a page which will send Email to Newsletter subscribers. There
I have made a page in which i m using a list to display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.