Created
June 2, 2013 02:40
-
-
Save mtasuandi/5692416 to your computer and use it in GitHub Desktop.
Fetching form fields without using RegEx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$genericform = HTML_FORM; | |
$document = new DOMDocument(); | |
$document->loadHTML(stripslashes($genericform)); | |
for($i=0; $i<$document->getElementsByTagName('input')->length; $i++) | |
{ | |
$htmlform = $document->getElementsByTagName('input')->item($i); | |
if($htmlform->attributes->getNamedItem('type')->value == 'hidden') | |
{ | |
$hiddenfields[][$htmlform->attributes->getNamedItem('name')->value] = $htmlform->attributes->getNamedItem('value')->value; | |
$hiddenfield[] = $htmlform->attributes->getNamedItem('name')->value; | |
$hiddenvalue[] = $htmlform->attributes->getNamedItem('value')->value; | |
} | |
if($htmlform->attributes->getNamedItem('type')->value == 'text' || $htmlform->attributes->getNamedItem('type')->value == 'email') | |
{ | |
$inputfield[] = $htmlform->attributes->getNamedItem('name')->value; | |
} | |
} | |
$form = $document->getElementsByTagName('form')->item(0); | |
$action = $form->attributes->getNamedItem('action')->value; | |
$method = $form->attributes->getNamedItem('method')->value; | |
foreach($hiddenfield as $hfield) | |
{ | |
$hidfield .= $hfield.':'; | |
} | |
foreach($hiddenvalue as $hvalue) | |
{ | |
if($hvalue == ''){$hidval='-';}else{$hidval=$hvalue;} | |
$hidvalue .= $hidval.':'; | |
} | |
$email = $inputfield[0]; | |
$name = $inputfield[1]; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment