Use PHP Check all the field in form is not empty,here is the php page–continues with previous post

Use PHP Check all the field in form is not empty,here is the php page–continues with previous post

<?php
/*  Program name: checkBlank.php
 *  Description:  Program checks all the form fields for
 *                blank fields.
 */
 if(isset($_POST[‘sent’]) && $_POST[‘sent’] == “yes”)        #6
 {
/* check each field except middle name for blank fields */
  foreach($_POST as $field => $value)                        #9
  {
  if($value == “”)                                          #11
    {
      if($field != “middle_name”)                           #13
      {
         $blank_array[] = $field;                           #15
      } // endif field is not middle name
    } // endif field is blank
    else                                                    #18
    {
      $good_data[$field] = strip_tags(trim($value));
    }
  }  // end of foreach loop for $_POST
  /* if any fields were blank, create error message and
     redisplay form */
  if(@sizeof($blank_array) > 0)                             #25
  {
    $message = “<p style=’color: red; margin-bottom: 0;
         font-weight: bold’>
         You didn’t fill in one or more required fields.
         You must enter:
         <ul style=’color: red; margin-top: 0;
             list-style: none’ >”;
    /* display list of missing information */
    foreach($blank_array as $value)
    {
      $message .= “<li>$value</li>”;
    }
    $message .= “</ul>”;
    /* redisplay form */
    extract($good_data);                                     #40
    include(“form_phone_values.inc”);                        #41
    exit();                                                  #42
  } // endif blanks
  echo “All required fields contain information”;            #44
 } // endif submitted
 else                                                        #46
 {
  include(“form_phone_values.inc”);
 }
?>

Advertisements

Use PHP Check all the field in form is not empty–continues

First use class create your php form page,here is your class, you could save as form_phone_values.inc

<?php
/*  Program name: form_phone_values.inc
 *  Description:  Defines a form that collects a user’s
 *                name and phone number.
 */
$labels = array( “first_name” => “First Name”,
                 “middle_name” => “Middle Name”,
                 “last_name” => “Last Name”,
                 “phone” => “Phone”);
$submit = “Submit Phone Number”;
?>
 <html>
 <head><title>Customer Phone Number</title>
    <style type=’text/css’>
    <!–
     #form {
       margin: 1.5em 0 0 0;
       padding: 0;
     }
     #field {padding-bottom: 1em;}
     label {
     font-weight: bold;
     float: left;
     width: 20%;
     margin-right: 1em;
     text-align: right;
     }
    –>
   </style>
 </head>
 <body>
<h3>Please enter your phone number below.</h3>
<?php
 echo “<form action=’$_SERVER[PHP_SELF]’ method=’POST’>    
      <div id=’form’>”;
  if(isset($message))                                         #36
  {
     echo $message;
  }
  /* Loop that displays the form fields */
  foreach($labels as $field => $label)
  {
    echo “<div id=’field’><label for=’$field’>$label</label>
          <input id=’$field’ name=’$field’ type=’text’
             size=’50%’ maxlength=’65’
             value='”.@$$field.”‘ /></div>\n”;                #46
  }
  echo “<input type=’hidden’ name=’sent’ value=’yes’ />\n”;     #48
  echo “<input style=’margin-left: 33%’ type=’submit’
          value=’$submit’ />\n”;
?>
</form></body></html>

Use PHP displayGallery

Instead use PHP display images from your databases, Use PHP displays all the image files that are stored in a specified directory.

here is the source code:

<?php
 /* Script name: displayGallery
  * Description: Displays all the image files that are
  *              stored in a specified directory.
  */
 echo “<html><head><title>Image Gallery</title></head>
       <body>”;
 $dir = “small/”;                                #8
 $dh = opendir($dir);                                       #9
 while($filename = readdir($dh))                           #10
 {
   $filepath = $dir.$filename;                             #12
   if(is_file($filepath) and ereg(“\.jpg$”,$filename))     #13
   {
      $gallery[] = $filepath;
   }
 }
 sort($gallery);                                           #16
 foreach($gallery as $image)                               #17
 {
   echo “<hr />”;
   echo “<img src=’$image’ /><br />”;
 }
?>
</body></html>

What is Skin in asp.net?

Skins are simple text files that contain markup that enables you to define the look and feel of one or more server controls from a central location. Placed in a theme’s folder, they are an integral part of the ASP.NET themes feature. A skin file (with a .skin extension) contains the server-side presentational elements of a control. These settings are then applied to all the controls to which the skin  applies.

Skin markup is similar to the markup of a button. There are a few differences though. First of all, the control in the skin file cannot have an ID attribute. The ID is used to uniquely identify a control in a page, and because the skin is applied to all controls, there’s no point in giving it an ID. Another difference is the number of attributes you can set in the markup. Not all properties of a control are skinnable.

Generally speaking, properties that influence the appearance (BackColor, ForeColor, BorderColor, and so on) can be skinned and properties that influence behavior (Enabled, EnableViewState, and
more) cannot be set.

Use Cookie to Dynamically Switching Themes

Cookies are little pieces of text that you can store on the user’s computer. The data you store in a cookie is sent only to the server that set it in the first place, so other sites can’t read the cookie from
yours. However, because cookies are stored on the user’s computer as plain text, you should never use them to store any sensitive data, such as a password. Storing harmless data like the preferred
theme is an excellent use of cookies, though.

There has been a lot of debate about cookies and whether or not they can harm your privacy. Generally, cookies are safe, because they only store data that the server that sets it already has. They can’t be used to steal sensitive data from your computer if you haven’t given this data to the server yourself. In most scenarios, cookies improve the user’s browsing experience by remembering little pieces of data instead of asking you every single time you visit a page. Unfortunately, some large corporations like advertising agencies use a unique cookie to track your trails on the web, giving them some global idea of the sites you visit. To ensure that visitors to your site understand what information you have and keep about them, it’s usually a good idea to add a privacy statement to your site describing the intent and usage of cookies and any personal data you may keep.

To apply a theme to your web site, you have three different options: at the page level in the Page directive, at the site level by modifying the web.config file, and programmatically

To apply a theme to your web site, you have three different options: at the page level in the Page directive, at the site level by modifying the web.config file, and programmatically.

  • Setting the theme at the page level: Setting the Theme or StyleSheetTheme property at the page level is easy: just set the relevant attribute in the Page directive of the page:
    <%@ Page Language=”VB” AutoEventWireup=”false” CodeFile=”Default.aspx.vb” Inherits=”_Default” Theme=”DarkGrey” %>
  • Setting the theme at the site level: To enforce a theme throughout the entire web site, you can set the theme in the web.config file by adding a theme attribute to the <pages> element
    inside the <system.web> element:
    <pages theme=”DarkGrey”>

    </pages>
    Make sure you type theme with all lowercase letters because the XML in the web.config file is case sensitive.
  • Setting themes programmatically: The third and final way to set a theme is programmatically through code.

Choosing Between Theme and StyleSheetTheme

Because properties of the StyleSheetTheme can be overridden by the page, and the Theme in turn can override these properties again, both serve a distinct purpose. You should set
the StyleSheetTheme if you want to supply default settings for your controls. That is, the StyleSheetTheme can supply defaults for your controls, which can then be overridden at the page
level. You should use the Theme property instead if you want to enforce the look and feel of your controls. Because the settings from the Theme cannot be overridden anymore and effectively overwrite any customizations, you can be assured that your controls look the way you defined them in the theme. There is one exception: by setting EnableTheming on the control to False you can disable theming for that control.

Different Types of Themes

An ASP.NET page has two different properties that enable you to set a theme: the Theme property and the StyleSheetTheme property. Both of these properties use the themes that you define in the App_Themes folder. Although at first they seem very similar, it’s their runtime behavior that makes the difference. The StyleSheetTheme is applied very early in the page’s life cycle, shortly after the page instance has been created. This means that an individual page can override the settings from the theme by applying inline attributes on the controls. So, for example, a theme with a skin file that sets the BackColor of a button to purple can be overridden by the following control declaration in the markup of the page:
<asp:Button ID=”Button1” runat=”server” Text=”Button” BackColor=”Red” />
The theme in the Theme property, on the other hand, is applied late in the page’s life cycle, effectively overriding any customization you may have for individual controls.

ASP.NET Page Life Cycle

  • Page request A request to an ASPX page starts the life cycle of that page. When the web server is able and allowed to return a cached copy of the page, the entire life cycle is not executed. In all other situations, the page enters the start phase.
  • Start In this phase, the page gets access to properties like Request and Response that are used to interact with the page’s environment. In addition,during this phase the PreInit event is raised to signal that the page is about to go into the initialization phase.
  • Page initialization During this phase, the controls you have set up in your page or added programmatically become available. Additionally, the Page class fires three events: Init, InitComplete, and PreLoad. Also during this phase, the control properties are loaded from View State and Control State again during a postback. So, for example, when you change the selected item in a DropDownList and then cause a postback, this is the moment where the correct item gets preselected in the drop-down list again, which you can then work with in your server-side code.
  • Load During this phase the page raises the Load event.
  • Validation In the validation phase, the Validation controls used to validate user input are processed.
  • Postback event handling During this phase, the controls in your page may raise their own events. For example, the DropDownList may raise a SelectedIndexChanged event when the user has chosen a different option in the list. Similarly, a TextBox may raise the TextChanged event when the user has changed the text before she posted back to the server. When all event processing is done, the page raises the LoadComplete event. During this phase the PreRender event is raised to signal that the page is about to render to the browser. Shortly after that, SaveStateComplete is raised to indicate that the page is done storing all the relevant data for the controls in View State.
  • Rendering Rendering is the phase where the controls (and the page itself) output their HTML to the browser.
  • Unload The unload phase is really a clean-up phase. This is the moment where the page and controls can release resources like database connections.During this phase, the Unload event is raised so you can handle any cleanup you may need to do.