Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Explain in brief validating form field using JavaScript ?

Validating Form Fields Using JavaScript in FrontPage

Validating a submitted user is important as it may contain inappropriate values. So the belief is essential.

Javascript provides you the facility that validates the form on the client side, so processing will be faster than server-side validation. Therefore, most web developers prefer JavaScript form validation.

By javascript, we can validate names, passwords, email, date, mobile number etc. fields.

Basic belief - First of all, this form should ensure that all mandatory fields are filled. It will require just one loop through each field in the form and check for the data.

Data Format Validation - Second, the data that is entered should be checked for the correct form and value. To verify the accuracy of the data, your code contains the correct logic.

JavaScript Example

<html> <body> <script> function validateform(){ var; var password=document.myform.password.value; if (name==null || name==""){ alert("Name can't be blank"); return false; }else if(password.length<6){ alert("Password must be at least 6 characters long."); return false; } } </script> <body> <form name="myform" method="post" action="valid.php" onsubmit="return validateform()" > Name: <input type="text" name="name"><br/> Password: <input type="password" name="password"><br/> <input type="submit" value="register"> </form> </body> </html>


Explain in brief how pie chart can be drawn in php GD library.

Getting Fancy with Pie Charts

A little boring, but they introduced you to the process of creating images—define the canvas, define the colors, and then draw and fill. 

Use this same sequence of events to expand your scripts to create charts and graphs, using either static or dynamic data for the data points.

Draws a basic pie chart.

    //create the canvas 
 $myImage = ImageCreate(150,150); 

 //set up some colors 
 $white = ImageColorAllocate($myImage, 255, 255, 255); 
 $red  = ImageColorAllocate($myImage, 255, 0, 0); 
 $green = ImageColorAllocate($myImage, 0, 255, 0);
 $blue = ImageColorAllocate($myImage, 0, 0, 255);
 //draw a pie 
 ImageFilledArc($myImage, 50, 50, 100, 50, 0, 90, $red, IMG_ARC_PIE);
 ImageFilledArc($myImage, 50, 50, 100, 50, 91, 180 , $green, IMG_ARC_PIE);
 ImageFilledArc($myImage, 50, 50, 100, 50, 181, 360 , $blue, IMG_ARC_PIE);
 //output the image to the browser
 header ("Content-type: image/jpeg");
 //clean up after yourself

Out put

which has several attributes: 

  1. The image identifier.
  2. The partial ellipse centered at x.
  3. The partial ellipse centered at y.
  4. The partial ellipse width.
  5. The partial ellipse height.
  6. The partial ellipse start point.
  7. The partial ellipse end point.
  8. Color.
  9. Style.

Combine HTML and PHP code on single page explain in brief?

Combine HTML and PHP code on 

single page explain in brief?


While creating a complex page, at times you will need to use PHP and HTML to achieve your essential results. 

At first point, this seems complicated, because PHP and HTML are two separate languages, but this is not the case. 

PHP is designed to communicate with HTML and PHP scripts, it can be included in the HTML page without any problems.

Take the following, as an example

<?php echo "The solution to 2 + 2 is "; ?>
<?php echo 2 + 2; ?>
OutPutThe solution to 2 + 2 is 4

There’s really no reason to include two sets of opening and closing tags. You could easily just write
PHP files can contain both static text and executable PHP code. 
Whether or not a specific part of the file is rendered directly as text, or intepreted as PHP code is down to the use of the opening and closing PHP tags. 
Whenever the code is between the <?php and ?> tags, it will be executed as PHP code.
<html>   <head>       <title><?php echo "My Fiest Program";?></title>   </head><body>
<?php echo "<h1>Hello India</h1>"; ?>

Out PutHello India