3/22/15

HTML Form Action


Action is used to give reference/link of another page.
If we want to separate the business logic (PHP script) from Presentation layer (HTML script) then we use Action attribute of Form .
It reduce the complexity of bulk of codes. Because All scripts are separately define on their own page.
In the previous Form Post method PHP script and HTML script were define on the same page ,so it show the design part with the output of program.
But using Action property HTML script define on a separate page and Business logic(PHP script) on another separate page.
eg.
    Save it as DesingView.php
 <body>
 <form method="post" action="Logic.php">
   <table border="1" align="center">
    <tr>
  <td>Enter your name</td>
  <td><input type="text" name="n"/></td>
    </tr>
    <tr>
  <td colspan="2" align="center">
   <input type="submit" name="sub" value="SHOW MY NAME"/>
  </td>
    </tr>
   </table>
  </form>
 </body> 
 

    Save it as Logic.php 
 <?php
 
  $name=$_POST['n'];
  echo "Welcome ".$name;
 ?>
  
   Enter your name
     
    

    Output:  Welcome Sanjeev
First we make Form using html script. we design a textbox to take input through user and a submit button with value(“show my name”) .
When name is entered by user and click on submit button the value of textbox redirect to php script page. Because Action Attribute is used here for link .
Information that is send by user is collect by using $_POST[] and store in a local variable($name).
Now a local variable is concatenate with String(“welcome”) and print, output will become Welcome Sanjeev.

Related Posts:

  • PHP Syntax PHP Environment Start – End syntax is a way to representation of PHP script. Basically it gives the primary idea to specify the code for… Read More
  • PHP WAMP Installation WAMP Server Installation Steps Step:1 Download latest wamp software(64bit for 64bit os and 32bit for 32bit os) Step:2 click on setup Ste… Read More
  • PHP Software Requirement PHP Servers The PHP Community Provides Some types of Software Server solution under The GNU (General Public License). These are the following:… Read More
  • PHP Advantage Unique Features Of PHP Unique Features Performance Portability Ease Of Use Open Source Third-Party Application Support Community Support … Read More
  • PHP Variables Variables in PHP Variable is nothing it is just name of the memory location. A Variable is simply a container i.e used to store both nu… Read More

0 comments:

Post a Comment

FIND US ON FACEBOOK

FIND US ON Twitter