When i use "print_r($_POST)" it just captured "name" of input. How to get parameter input, such as "type" or "name" from html form :
<form method="post">Nama : <input type="text" name="nama" /><br />
Jabatan : <input type="hidden" name="id_jabatan" value="2"><br>
Kontak : <input type="text" name="kontak"><br>
Email : <input type="text" name="email"><br>
UserID : <input type="text" name="userid"><br>
Foto : <input type="file" name="foto"><br>
<br>
<input type="submit" value="Simpan" name="simpan">
</form>
I filled up that form with this values : AA 2 W CC dD Simpan
This is result of "print_r($_POST)" :
Array
(
[nama] => AA
[id_jabatan] => 2
[kontak] => VV
[email] => CC
[userid] => dD
[foto] =>
[simpan] => Simpan
)
just name of input captured Please help :)
Any piece of information from the session array is available using the following function: $this->session->userdata('item');
Where item is the array index corresponding to the item you wish to fetch. For example, to fetch the session ID you will do this: $session_id = $this->session->userdata('session_id');
Note: The function returns FALSE (boolean) if the item you are trying to access does not exist. try something like this
$sessiondata = array(
'username' => $username,
'password'=>$password,
'email'=>$email,
'is_login' => TRUE
);
//$this->login_model->set_session($username);
$this->session->set_userdata($sessiondata);
print_r($this->session->all_userdata()); //to check
What about passing the type of the input field in its name like this :
<form method="post">
Nama : <input type="text" name="text[nama]" /><br>
Jabatan : <input type="hidden" name="hidden[id_jabatan]" value="2"><br>
Kontak : <input type="text" name="text[kontak]"><br>
Email : <input type="text" name="text[email]"><br>
UserID : <input type="text" name="text[userid]"><br>
Foto : <input type="file" name="file[foto]"><br>
<input type="submit" value="Simpan" name="simpan">
</form>
Then :
var_dump($_POST);
Gives something like this :
'text' =>
array (size=4)
'nama' => string '' (length=0)
'kontak' => string '' (length=0)
'email' => string '' (length=0)
'userid' => string '' (length=0)
'hidden' =>
array (size=1)
'id_jabatan' => string '2' (length=1)
'file' =>
array (size=1)
'foto' => string 'file' (length=4)
'submit' => string 'send' (length=4)
Hope that can help.
Here is a simple example demonstrating the use of PHP Simple HTML DOM Parser.
It demonstrates accessing the 'type' and 'value' of the input fields.
<?php
include __DIR__ .'/vendor/simplehtmldom_1_5/simple_html_dom.php';
// restrict the list of names to use
$inputNames = array("nama", "kontak", "email", "userid", "foto", "id_jabatan", "simpan");
if (empty($_POST)) { // supply default values
$_POST = array();
foreach ($inputNames as $name) {
$_POST[$name] = '';
}
}
$html = <<<EOF
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
</head>
<body>
<form action="" method="post">
Nama : <input type="text" name="nama" value="{$_POST['nama']}" ><br />
Kontak : <input type="text" name="kontak" value="{$_POST['kontak']}"><br />
Email : <input type="text" name="email" value="{$_POST['email']}"><br />
UserID : <input type="text" name="userid" value="{$_POST['userid']}"><br />
Foto : <input type="file" name="foto" value="{$_POST['foto']}"><br />
<input type="hidden" name="id_jabatan" value="2"><br>
<br />
<input type="submit" value="Simpan" name="simpan">
</form>
</body>
</html>
EOF;
// parse the HTML and the POST inputs.
if (!empty($_POST)) {
$htmlDom = str_get_html($html);
// find all the elements with a name
$elements = $htmlDom->find('[name]');
foreach ($elements as $node) {
if (!in_array($node->attr['name'], $inputNames)) {
continue; // ignore
}
echo 'The Name is: ', $node->attr['name'], ' ',
'The Tag/Type is: ', $node->tag, ' ', ' / ', $node->attr['type'], ' ',
'The Value is: ', $node->attr['value'], '<br />';
}
}
// show the form with the current values.
echo '<br />';
echo $html;
exit;
Output:
The Name is: nama The Tag/Type is: input / text The Value is:
The Name is: kontak The Tag/Type is: input / text The Value is:
The Name is: email The Tag/Type is: input / text The Value is: xxx@ttt
The Name is: userid The Tag/Type is: input / text The Value is:
The Name is: foto The Tag/Type is: input / file The Value is: Winter.jpg
The Name is: id_jabatan The Tag/Type is: input / hidden The Value is: 2
The Name is: simpan The Tag/Type is: input / submit The Value is: Simpan
Nama :
Kontak :
Email :
UserID :
Foto :