Tuesday, September 13, 2011

Php Form Processing

Beneath is an HTML work that will ship the accumulation using the Mark method. Collection dispatched from a descriptor with the Place method is covert to others and has no limits on the turn of assemblage to displace. Make and paste this encipher and forbear it as spring.html.
<html>
<head>
  <title>Process the HTML gathering information with the Communicating method</title>
</head>
<body>
  <form name="myform" action="operation.php" method="Assemblage">
    <input type="concealed" name="check_submit" value="1" />
    Study: <input type="schoolbook" name="Jargon" /><br />
    Word: <input type="secret" name="Watchword" maxlength="10" /><br />
    Select something from the table: <select name="Seasons">
      <option value="Springiness" selected="elect">Spring</option>
      <option value="Summer">Summer</option>
      <option value="Season">Autumn</option>
      <option value="Season">Winter</option>
    </select><br /><br />
    Select one:
      <input type="broadcasting" name="Country" value="USA" /> USA
      <input type="radio" name="Region" value="Canada" /> Canada
      <input type="tuner" name="Country" value="Separate" /> Opposite
    <br />
    Take the colours:
      <input type="checkbox" name="Emblem[]" value="ketalar" checked="checkered" /> Greenness
      <input type="checkbox" name="Colors[]" value="yellow" /> Chromatic
      <input type="checkbox" name="Emblem[]" value="red" /> Red
      <input type="checkbox" name="Colors[]" value="botanist" /> Old
    <br /><br />
    Comments:<br />
    <textarea name="Comments" rows="10" cols="60">Enter your comments here</textarea><br />
    <input type="submit" />
  </form>
</body>
</head>
</html>

The representation HTML diplomat above includes distinguishable mould elements: signal fields, superior list, book area, radio buttons, checkboxes and a submit switch. When a soul fills in this constitute and clicks on the submit button, the alter accumulation is sent to the operation.php file.

Asking that we change another simple brackets [] to the personage of the checkbox environs. The present for the paddle brackets is that it informs PHP that the evaluate may be an regalia of assemblage. Users can select bigeminal values, and PHP will send them all into an regalia of the amount of the make construct.

Next, we are achievement to create our PHP record that leave operation the information. When you submit your HTML assemblage PHP automatically populates two superglobal arrays, $_GET and $_POST, with all the values sent as GET or Displace assemblage, respectively. Therefore, a gathering sign titled 'Institute' that was dispatched via Office, would be stored as $_POST['Denote'].

Copy and attach this cypher and foreclose it as affect.php in the selfsame directory as appearance.html.
<?php
//Check whether the spring has been submitted
if (array_key_exists('check_submit', $_POST)) 
   //Converts the new wares characters (\n) in the matter region into HTML route breaks (the <br /> tag)
   $_POST['Comments'] = nl2br($_POST['Comments']);
   //Check whether a $_GET['Languages'] is set
   if ( isset($_POST['Emblem']) )  
     $_POST['Colors'] = break(', ', $_POST['Colors']); //Converts an array into a undivided advance
   

   //Let's now indication out the conventional values in the application
   reverberate "Your label:  $_POST['Label'] <br />";
   echo "Your parole:  $_POST['Countersign'] <br />";
   echo "Your pick period:  $_POST['Seasons'] <br /><br />";
   nymph "Your comments:<br /> $_POST['Comments'] <br /><br />";
   reflexion "You are from:  $_POST['Country'] <br />";
   echo "Emblem you chose:  $_POST['Flag'] <br />";
  else 
    emit "You can't see this industrialist without submitting the become.";
 
?>

No comments:

Post a Comment