Page 1 of 1

Change font colour dynamically ?

Posted: Sun Jan 24, 2010 2:50 pm
by MiniMonty
Hi all,

I have form which inserts new users into a DB.
The form has a "Terms and Conditions" checkbox which must be checked.
Is there a way of setting a new colour for the font if users don't check the box
ad then hit the Submit button ?
i.e. - hit the button, page reloads with the text next to the text box turned red ?
The text is a variable "termsMsg".
Code below:

Best wishes
Monty

Form

Code: Select all

 
////////////////   INSERT THE STUDENT INTO THE students_to_courses TABLE  
$termsMsg ="I have read and agree with the terms and conditions";
if (isset ($_POST['terms_box'])){
 
     $sql = mysql_query("INSERT INTO `students_to_courses` ( `id` , `student_fk` , `course_fk` , `course_completed` ) 
    VALUES ('', '$id', '2', '0')")
     or die (mysql_error());
     $id = mysql_insert_id(); 
         
    $msgToUser = "Top Stuff <span class=orangeText>$firstname</span>, you are signd up to <br><span class=Big_Blue_Times>Tune In To Programs !</span> <br>
        Your download should start automatically and this course will now appear <br>
        on the list of "Your Courses". You can click that link upload your coursework<br>
      when you're ready. But enjopy the course first ! ";
    
   include_once 'msgToUser.php';
 
   exit();
      
}
 

html section:

Code: Select all

 
 <td height="53"><form name="student_course_insert" method="post" action="signup_course2.php">
              <div align="left"><br>
                  <?php print $termsMsg ?> 
                    <input name="terms_box" type="checkbox" id="terms_box" value="checkbox">
                  <br>
                  Sign Me Up ! &nbsp;&nbsp;
                  <input type="submit" name="SignUp" value="Submit">
                  <br>
                </div>
            </form></td>
 

Re: Change font colour dynamically ?

Posted: Sun Jan 24, 2010 3:37 pm
by JakeJ
Determine in your processing form if the box has been checked using isset(), if false, set a variable with the html code to what you want the box to be. Also, in your html form, use an isset() to test $GET[]. If it's true, then return the code for the new box in to your form rather than the original code.

Re: Change font colour dynamically ?

Posted: Sun Jan 24, 2010 3:39 pm
by a.heresey
I would add a conditional to the terms variable so that it is red when $_POST['terms_box'] is unset. This would also make the text red when you first load the page though. You would also need to add a variable that checks if this is the first time the page was loaded.
This could go after line 3 to make it red and keep it black the first time on the page.

Code: Select all

 
if(!isset($_POST['SignUp'])){
//form hasn't been submitted. Chill.
$termsMsg='<span class="blacktext">'.$termsMsg .'</span>';
}else{
//form has been submitted, but they're still on this page. Must have not checked box. Give them a clue.
$termsMsg='<span class="redtext">'.$termsMsg .'</span>';
}