Format echo with CSS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dmwesq
Forum Newbie
Posts: 21
Joined: Wed Jan 23, 2008 4:35 pm

Format echo with CSS

Post by dmwesq »

I am trying to format a line of text that is echoed using CSS following some code I found online, but can't get it to work. When I click on the created class it shows no CSS exists. I had put the style in my styles within the page, which is a combination of php and html all in one.

The code I was following is:

Code: Select all

<!-- css -->
p.paragraph {
text-align: center;
color: #000;
}
<?php
echo '<p class="paragraph">Thank you. We will be contacting you shortly with our best price for your request. Back to site home page</p';?>
The code I have is

p.para {
font-size:large;
font-style:italic;
text-align:center;
}

Code: Select all

echo "<p class='para'>Thanks for submitting the permission form for $activity</p>";
I switched the single and double quotes because it did not work with the original single around the echo and double on the class and another site suggested this change.
dmwesq
Forum Newbie
Posts: 21
Joined: Wed Jan 23, 2008 4:35 pm

Re: Format echo with CSS

Post by dmwesq »

I ran a test with just the code from a sample alone and it worked fine, with single and double quotes as is. I also noted in the sample that the <span> was outside the php, but the code would work even if I removed the <span> tag and just went with the <p class> inside the echo. The css also showed up when I clicked on the class, which it doesn't do in my actual file.

Code: Select all

<!-- css -->
<style type="text/css">
<!--
.paragraph {
text-align: center;
color: #00CC66;
}
-->
</style>

<span class="paragraph">
<?php
echo '<p class="paragraph">Thank you. We will be contacting you shortly with our best price for your request. Back to site home page</p';?>
</span>
However, when I tried this on my file, no formatting worked no matter how I tried - with or without span tags, etc. Span tag also stopped the echo from echoing my variable. I'm very frustrated.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Format echo with CSS

Post by social_experiment »

Code: Select all

 <p class="paragraph">Thank you. We will be contacting you shortly with our best price for your request. Back to site home page</p'
You forgot a closing tag at the end of this line.

Remove either the span tags or the paragraph tags, two of the same classes (in different tags) are moot as your css will work with either one.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
dmwesq
Forum Newbie
Posts: 21
Joined: Wed Jan 23, 2008 4:35 pm

Re: Format echo with CSS

Post by dmwesq »

The code that had the missing end tag is not the code I'm concerned with - that was the sample code, which by the way worked fine even with the missing tag. It is the other code with the class "para" that I am trying to solve. I have tried it with and without both span and paragraph classes, using each individually, etc - just still won't work.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Format echo with CSS

Post by social_experiment »

dmwesq wrote:The code that had the missing end tag is not the code I'm concerned with - that was the sample code, which by the way worked fine even with the missing tag.
You won't be concerned with it now but just try to validate that html code, then you will notice it's absence.

Do you only have one the CSS for the para class or the code for the para class and the paragraph class?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
dmwesq
Forum Newbie
Posts: 21
Joined: Wed Jan 23, 2008 4:35 pm

Re: Format echo with CSS

Post by dmwesq »

Again, the code I need to focus on is my own, not the sample code which I have borrowed from. I've tried my code with variations including closing tags, using P class, span class, etc.

Here is my current CSS:
.para {
text-align: center;
color: #00CC66;
}

And my closing php:

Code: Select all

<?php

}
else {
  

mail( "info@*****.org", "Permission Form",
"Activity: $activity\n
Activity Date: $activity_date\n
Location: $location\n
Scout Name: $scoutname\n
Others Attending: $attending\n
Parent/Guardian: $parent\n
Email: $email\n
Primary Phone: $primaryphone\n
Alternate Phone: $alternatephone\n
Alternate Contact: $alternatecontact\n
Alternate Contact Phone: $alternatecontactphone\n
Any Medical Change Since Last Physical: $physical\n
Describe Changes: $other\n
Any change in medications: $medicine\n
Describe Changes: $other2\n
Is Parent/Guardian Transporting: $transport\n
If yes, number of other scouts you can transport: $scouts\n
If not, have transport arrangements been made: $transport2\n
Name of family transporting: $other3\n
Legal Acknowledgement: $legal\n
List any additional information: $additional",
	"From: $email" );
header ('Refresh: 5; http://www.*****.org/events.shtml');
echo "<span class='para'>Thanks for submitting the permission form for $activity.</span>";
}
?>	
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Format echo with CSS

Post by cpetercarter »

Where is your CSS? In a style sheet, or as part of the head section of your html? If it is in a style sheet, check that you haven't made a error in the link to your style sheet (eg specifying a wrong path). Then clear the browser cache. Browsers frequently cache style sheets, and don't always notice when they have changed.
dmwesq
Forum Newbie
Posts: 21
Joined: Wed Jan 23, 2008 4:35 pm

Re: Format echo with CSS

Post by dmwesq »

The Css for this is in the head section of this page with other styles specific to this page.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Format echo with CSS

Post by social_experiment »

Does your other style settings work?
EDIT
Are there any errors from this? Headers already being sent?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Format echo with CSS

Post by cpetercarter »

It's because you are using the "echo" command.

If you have a page of mixed html and php, the php is parsed and executed first, and the html afterwards. The style bit in your head section is outside the <?php ... ?> tags, I guess, so it will be sent to the browser after the echo command has sent "Thanks for submitting the permission form for $activity".

What to do about it? Well, the real solution is to write your code so that the logic (basically the php) and the presentation (html) are completely separate. But for a quick fix you could just do:

Code: Select all

echo '<span style="text-align: center; color: #00CC66;">Thanks for submitting the permission form for $activity</span>';
s992
Forum Contributor
Posts: 124
Joined: Wed Oct 27, 2010 3:06 pm

Re: Format echo with CSS

Post by s992 »

I'm pretty sure that's incorrect, cpetercarter.

dmwesq, I don't think it's a php problem. I would check and double check to make sure everything is spelled right, no missing semicolons or closing braces, etc, etc.
dmwesq
Forum Newbie
Posts: 21
Joined: Wed Jan 23, 2008 4:35 pm

Re: Format echo with CSS

Post by dmwesq »

I'm still stuck with my formatting issue. I have everything working fine - the echo gives back my message including the variable, the redirect works fine, but each time I try to add any css into this whether inline, or with a style, I get errors. If I put CSS code in style before the php I get headers already sent, and the reference goes back to whatever line has style=text/css. I am very confused and I guess I could live without the formatting but I know it is supposed to be able to be done - just can't figure out how.

Code: Select all

<?php
$activity = $_POST['activity'];
$activity_date = $_POST['activitydate'];
$scout_name = $_POST['scoutname'];
$attending = $_POST['attending'];
$parent = $_POST['parent'];
$email = $_POST['email'];
$primary_phone = $_POST['primaryphone'];
$alternate_phone = $_POST['alternatephone'];
$alternate_contact = $_POST['alternatecontact'];
$alternate_contact_phone = $_POST['alternatecontactphone'];
$physical = $_POST['physical'];
$other = $_POST['other'];
$medicine = $_POST['medicine'];
$other2 = $_POST['other2'];
$transport = $_POST['transport'];
$scouts = $_POST['scouts'];
$transport2 = $_POST['transport2'];
$other3 = $_POST['other3'];
$legal = $_POST['legal'];
$additional = $_POST['additional'];

mail( "info@troop97newcity.org", "Troop 97 Permission Form", 
"Activity: $activity\n
Activity Date: $activitydate\n
Scout Name: $scoutname\n
Others Attending: $attending\n
Parent/Guardian: $parent\n
Email: $email\n
Primary Phone: $primaryphone\n
Alternate Phone: $alternatephone\n
Alternate Contact: $alternatecontact\n
Alternate Contact Phone: $alternatecontactphone\n
Any Medical Change Since Last Physical: $physical\n
Describe Changes: $other\n
Any change in medications: $medicine\n
Describe Changes: $other2\n
Is Parent/Guardian Transporting: $transport\n
If yes, number of other scouts you can transport: $scouts\n
If not, have transport arrangements been made: $transport2\n
Name of family transporting: $other3\n
Legal Acknowledgement: $legal\n
List any additional information: $additional", "From: $email" );
header ('Refresh: 5; http://www.troop97newcity.org/events.shtml');
echo ("Thanks for submitting your permission form for " . $activity.".");
?>	



User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Format echo with CSS

Post by social_experiment »

Can you place the code (the confirmation message) on the page that you are being refered to?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply