NOTICE

Adfly Links not working Find Direct Links HERE

How to build long forms using php in a short cut way

We can build a long form using php's foreach function in the following way. It makes the form more manageable and clean
<form name="myform" method="get" action="business.php" onsubmit="">
<?php

$postvalue=array("Name"=>"0","Email"=>"1","Phone"=>"2");
foreach($postvalue as $key => $value)
{
  echo ''.$key.'<input type="text" id="id'.$value.'" name="name['.$value.']" value=""><div id="err'.$value.'"></div><br>';
}

?>
<input type="submit" onclick="checkValidit()">
</form>
We can add any number of keys and values in array To get the values we can use following code
<?php
session_start();
$value = $_GET["name"];

foreach ($value as $uni) {
    $_SESSION[$uni] = $uni;
}

foreach ($value as $uni) {
    echo $_SESSION[$uni] . "<br>";
}
?>

0 comments :

Feel free to leave comment if you like above widget, have any questions or just say Hi! :)