Simple Question

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
ut1205
Forum Commoner
Posts: 32
Joined: Thu Jan 29, 2004 5:12 pm

Simple Question

Post by ut1205 »

I'm good at HTML but I'm having a problem with it when it is within PHP tags. In the statement below I want to insert "Align=Center". What't the right format?

Code: Select all

<?php
print_error("<b>Your E-Mail Address is Invalid</b>");


?>
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

We'd have to see the print_error function. It should be at the top of the file or in an included file starting with the code:

Code: Select all

function print_error($something)  &#123;
If you post that, we'll be able to help you.
ut1205
Forum Commoner
Posts: 32
Joined: Thu Jan 29, 2004 5:12 pm

See if this is what you need!

Post by ut1205 »

Code: Select all

<?php
function print_error($reason,$type = 0) {
   build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color, $style_sheet);
   // for missing required data
   if ($type == "missing") {
      if ($missing_field_redirect) {
         header("Location: $missing_field_redirect?error=$reason");
         exit;
      } else {
      ?>
      <p align="center"><b>The Form Was Not Submitted For the Following Reasons:</b></p>

      <ul><?
      echo $reason."\n";
      ?></ul>
      <p align="center"><b>Please use your browser's back button to return to the form and try again.</b><?
      }
   } else { // every other error
      ?>
      The form was not submitted because of the following reasons:<p>
      <?
   }
?>
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

OK, now you just have to change the function's HTML output. Maybe something like this?

Code: Select all

<?php
function print_error($reason,$type = 0) {
   build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color, $style_sheet);
   // for missing required data
   if ($type == "missing") {
      if ($missing_field_redirect) {
         header("Location: $missing_field_redirect?error=$reason");
         exit;
      } else {
      ?>
      <p align="center"><b>The Form Was Not Submitted For the Following Reasons:</b></p>

      <div align="center"><?
      echo $reason."\n";
      ?></div>
      <p align="center"><b>Please use your browser's back button to return to the form and try again.</b><?
      }
   } else { // every other error
      ?>
      The form was not submitted because of the following reasons:<p>
      <?
   } 
?>
ut1205
Forum Commoner
Posts: 32
Joined: Thu Jan 29, 2004 5:12 pm

Thanks

Post by ut1205 »

:D Thanks!!! Worked great. I'm sure there will be more questions to come.

Jim
ut1205
Forum Commoner
Posts: 32
Joined: Thu Jan 29, 2004 5:12 pm

Still Confused

Post by ut1205 »

:( Within the PHP open and close tags I've figured out the "Bold", "Underline", "Links",ect but I still can't figure out how to code "align=center". Shown below are plain "echo" statements that are aligned to the "left". Is there any code I can put in the statements themself to get them to align in the center of the page?

Code: Select all

<?php
 echo "<b><h3>Thank you for your message.</h3></b>\n";

   echo "<b><h3>If requested a reply will be sent within 24 hours.</h3></b>\n";
   
   echo "<b><h3>Click <a href="../index.php">Here</a> To Return.</h3></b>\n";

   echo "<br><br>\n";
?>
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

Simplified it a little:

Code: Select all

<?php
echo "<div align="center"><b><h3>Thank you for your message.\n";
echo "If requested a reply will be sent within 24 hours.\n";
echo "Click <a href="../index.php">Here</a> To Return.</h3></b></div>\n";
echo "<br><br>\n";
?>
To center something, just use <div align="center"> or use CSS to position it.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

or, even easier, use <center> and </center>
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post by DuFF »

True, but <center> is deprecated. It still works on all main browsers right now though.

Edit:
Hmm, seems that div align is also deprecated. You should be using CSS instead by now.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

i know its not the "correct" way of doing it but i usually just do things like:

if i need to align something inside PHP use:
<align=center>
it works exactly the same without the quotations, and works properly on the browsers ive tested such as:

Internet Explorer 6
Mozilla (latest version)
Mozilla Firebird (latest linux version)
Opera 7.0

dunno about netscape coz its a horrible browser so i wont use it, however you should use the escaped character method or heredoc

my $0.02
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Doesn't Mozilla and Netscape both use the Gecko engine?
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post by malcolmboston »

yep, but then again i dont like mozilla either and opera behavaes differently to every other browser

inactuality the only browsers i like are IE6 and Firebird
Post Reply