gitlez

Untitled

Nov 29th, 2011
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.57 KB | None | 0 0
  1. <?php
  2. function getPost(){
  3.   $return = Array(); // Create a return array to be manipulated in the for loop
  4.   $args = func_get_args(); // Get all the passed arguments to the function, place in an array $args
  5.   $cn = count($args); // Count the number of args, or you could use func_num_args();
  6.   for($i=0;$i<$cn;++$i){
  7.     $return[$args[$i]] = (isset($_POST[$args[$i]])? $_POST[$args[$i]] : ''); // check to see if there is a POST variable with the name, if there is, set it to the variable value, otherwise set to empty string
  8.   }
  9.   return (count($return) === 1)? $return[$args[0]] : $return; // If there is only the one variable passed, then simply return the value of the one, otherwise return an array.
  10. }
  11. list($mr_ms, $name, $surname, $telephone, $mobile, $other_phone, $address_1, $address_2, $locality, $postcode, $island, $status, $introduced_by, $notes) = getPost('mr_ms', 'name', 'surname', 'telephone', 'mobile', 'other_phone', 'address_1', 'address_2', 'locality', 'postcode', 'island', 'status', 'introduced_by', 'notes');
  12.  
  13. /**  Or Use
  14.  
  15. $mr_ms = getPost('mr_ms');
  16. $name = getPost('name');
  17. $surname = getPost('surname');
  18. ... etc ...
  19.  
  20. **/
  21. if($_SERVER['REQUEST_METHOD'] === 'POST'){
  22.   echo '<pre>';
  23.   print_r($_POST);
  24.   exit;
  25. }
  26.  
  27.  
  28. ?>
  29. <html>
  30.   <head>
  31.     <script language="javascript">
  32.       function add(type,name) { /** Changed **/
  33.         //Create an input type dynamically.
  34.         var element = document.createElement("input");
  35.      
  36.         //Assign different attributes to the element.
  37.         element.setAttribute("type", type);
  38.         element.setAttribute("value", ''); /**  Changed **/
  39.         element.setAttribute("name", name); /** Changed **/
  40.  
  41.      
  42.         var foo = document.getElementById("fooBar");
  43.      
  44.         //Append the element in page (in span).
  45.         foo.appendChild(element);
  46.       }
  47.     </script>
  48.   </head>
  49. <body>
  50.  
  51. <?php
  52. /**  form action changed for testing reset to whatever  **/
  53. /**  Opening and closing PHP will cause more load on your server, as each time you close and open PHP, the server has to start and stop the PHP parser.  **/
  54. echo <<<FORM
  55.   <form name="form" action="" method="post">
  56.     <table>
  57.       <tr>
  58.         <td>
  59.           Mr/Ms:
  60.           <select name="mr_ms">
  61.             <option value="Mr">Mr</option>
  62.             <option value="Ms">Ms</option>
  63.           </select>
  64.         </td>
  65.         <td>
  66.           Name:<br />
  67.           <input name="name" type="text" value="$name" />
  68.         </td>
  69.         <td>
  70.           Surname:<br />
  71.           <input type="text" name="surname" id="surname" value="$surname" />
  72.         </td>
  73.       </tr>
  74.       <tr>
  75.         <td>
  76.           Address 1:<br />
  77.           <input type="text" name="address_1" id="address_1" value="$address_1" />
  78.         </td>
  79.         <td>
  80.           Address 2:<br />
  81.           <input type="text" name="address_2" id="address_2" value="$address_2" />
  82.         </td>
  83.         <td>
  84.           Locality:<br />
  85.           <input type="text" name="locality" id="locality" value="$locality" />
  86.         </td>
  87.       </tr>
  88.       <tr>
  89.         <td>
  90.           Postcode:<br />
  91.           <input type="text" name="postcode" id="postcode" value="$postcode" />
  92.         </td>
  93.         <td>
  94.           Land:
  95.           <select name="land">
  96.             <option value="US" selected="selected">US</option>
  97.             <option value="UK">UK</option>
  98.           </select>    
  99.         </td>
  100.         <td>
  101.           Status:
  102.           <select name="status">
  103.             <option value="Owner">Owner</option>
  104.             <option value="Broker">Broker</option>
  105.             <option value="Estate Agent">Estate Agent</option>
  106.             <option value="Other">Other</option>      
  107.           </select>    
  108.         </td>
  109.       </tr>
  110.       <tr>
  111.         <td valign="top">
  112.           Introduced by:<br />
  113.           <input type="text" name="introduced_by" id="introduced_by" value="$introduced_by" />
  114.         </td>
  115.         <td colspan="2" rowspan="2">
  116.           Notes:<br />
  117.           <textarea cols="45" rows="5" name="notes" id="notes">$notes</textarea>
  118.         </td>
  119.       </tr>
  120.       <tr>
  121.         <td valign="top" align="right">
  122.           <input type="submit" name="insert" id="insert" value="Add" />
  123.         </td>
  124.       </tr>
  125.       <tr>
  126.         <td colspan="3">
  127.           <input type="hidden" name="element" />
  128.           <!-- Changed -->
  129.           <input type="button" value="Add Phones" onclick="add('text','additionalPhones[]');" />
  130.           <!-- Changed -->
  131.           <br />
  132.           <span id="fooBar"></span>
  133.         </td>
  134.       </tr>
  135.     </table>
  136.   </form>
  137. FORM;
  138.  
  139. ?>
  140. </body>
  141. </html>
  142.  
Advertisement
Add Comment
Please, Sign In to add comment