Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function getPost(){
- $return = Array(); // Create a return array to be manipulated in the for loop
- $args = func_get_args(); // Get all the passed arguments to the function, place in an array $args
- $cn = count($args); // Count the number of args, or you could use func_num_args();
- for($i=0;$i<$cn;++$i){
- $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
- }
- 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.
- }
- 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');
- /** Or Use
- $mr_ms = getPost('mr_ms');
- $name = getPost('name');
- $surname = getPost('surname');
- ... etc ...
- **/
- if($_SERVER['REQUEST_METHOD'] === 'POST'){
- echo '<pre>';
- print_r($_POST);
- exit;
- }
- ?>
- <html>
- <head>
- <script language="javascript">
- function add(type,name) { /** Changed **/
- //Create an input type dynamically.
- var element = document.createElement("input");
- //Assign different attributes to the element.
- element.setAttribute("type", type);
- element.setAttribute("value", ''); /** Changed **/
- element.setAttribute("name", name); /** Changed **/
- var foo = document.getElementById("fooBar");
- //Append the element in page (in span).
- foo.appendChild(element);
- }
- </script>
- </head>
- <body>
- <?php
- /** form action changed for testing reset to whatever **/
- /** 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. **/
- echo <<<FORM
- <form name="form" action="" method="post">
- <table>
- <tr>
- <td>
- Mr/Ms:
- <select name="mr_ms">
- <option value="Mr">Mr</option>
- <option value="Ms">Ms</option>
- </select>
- </td>
- <td>
- Name:<br />
- <input name="name" type="text" value="$name" />
- </td>
- <td>
- Surname:<br />
- <input type="text" name="surname" id="surname" value="$surname" />
- </td>
- </tr>
- <tr>
- <td>
- Address 1:<br />
- <input type="text" name="address_1" id="address_1" value="$address_1" />
- </td>
- <td>
- Address 2:<br />
- <input type="text" name="address_2" id="address_2" value="$address_2" />
- </td>
- <td>
- Locality:<br />
- <input type="text" name="locality" id="locality" value="$locality" />
- </td>
- </tr>
- <tr>
- <td>
- Postcode:<br />
- <input type="text" name="postcode" id="postcode" value="$postcode" />
- </td>
- <td>
- Land:
- <select name="land">
- <option value="US" selected="selected">US</option>
- <option value="UK">UK</option>
- </select>
- </td>
- <td>
- Status:
- <select name="status">
- <option value="Owner">Owner</option>
- <option value="Broker">Broker</option>
- <option value="Estate Agent">Estate Agent</option>
- <option value="Other">Other</option>
- </select>
- </td>
- </tr>
- <tr>
- <td valign="top">
- Introduced by:<br />
- <input type="text" name="introduced_by" id="introduced_by" value="$introduced_by" />
- </td>
- <td colspan="2" rowspan="2">
- Notes:<br />
- <textarea cols="45" rows="5" name="notes" id="notes">$notes</textarea>
- </td>
- </tr>
- <tr>
- <td valign="top" align="right">
- <input type="submit" name="insert" id="insert" value="Add" />
- </td>
- </tr>
- <tr>
- <td colspan="3">
- <input type="hidden" name="element" />
- <!-- Changed -->
- <input type="button" value="Add Phones" onclick="add('text','additionalPhones[]');" />
- <!-- Changed -->
- <br />
- <span id="fooBar"></span>
- </td>
- </tr>
- </table>
- </form>
- FORM;
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment