Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

another PCRE question: need to match either display:none or visibility:hidden in the style attribute.

Posted on 2011-09-09
2
273 Views
Last Modified: 2012-06-21
hi there, the style attribute is retrieved using the php html dom class. i have used a regular expression to find either or, as in line 7 of the following function:
function ishidden($name,$html) {
	$str = str_get_html($html);
	$parent = $str->find("[name=".$name."]",0);
	while ($parent = $parent->parent()) {
		if (preg_match("/(display|visibility)\s*:\s*(none|hidden)/i",$parent->$style,$match)) {
			//print_r($parent);
			echo "style = ".$parent->$style."\n";
			return $match[0];
		}
	}
	return false;
}

function getforms($html) {
	/*
	- load form as:
	  array(
	   [type],
	   [name],
	   [value],
	   [checked],
	   [disabled]
	  );
	*/
	$ret = array();
	$forms = array();
	preg_match_all("/\<form [^\>]+\>.*\<\/form\>/ims",
			$html,
			$out);
	//print_r($out);
	foreach ($out[0] as $form) {
		array_push($forms,$form);
	}
	foreach ($forms as $form) {
		//echo $form."\n";
		$pattern = '/<(form)(?=(?:[^>]*name="([^"]*))?)(?=(?:[^>]*action="([^"]*))?)' .
				 '|<(input)(?=(?:[^>]*type="([^"]*))?)(?=(?:[^>]*name="([^"]*))?)(?=(?:[^>]*value="([^"]*))?)(?=(?:[^>]*checked="([^"]*))?)(?=(?:[^>]*disabled="([^"]*))?)' .
				 '|<(textarea)(?=(?:[^>]*name="([^"]*))?)[^>]*>([^<]|<(?!\/textarea))(?=(?:[^>]*disabled="([^"]*))?)' .
				 '|<(select)(?=(?:[^>]*name="([^"]*))?)(?=(?:[^>]*disabled="([^"]*))?)' .
				 '|<(button)(?=(?:[^>]*name="([^"]*))?)(?=(?:[^>]*disabled="([^"]*))?)/i';
		//$pattern = '/\<(form).*name="([^"]+)".*action="([^")".*\>'.
		//		 '|\<(input).*type="([^"]+)".*name="([^"]+)".*value="([^"]+)".*checked="([^"]+)".*\/\>'.
		//		 '|\<(textarea).*name="([^"]+)".*\>(.*)*\<\/textarea\>'.
		//		 '|<(select).*name="([^"]+)".*>'.
		//		 '|<(button).*name="([^"]+)".*value="([^"]+)".*>/ims';
		preg_match_all($pattern,
					$form,
					$out,
					PREG_SET_ORDER);
		$out = array_non_empty_items($out);
		$i = 0;
		foreach ($out as $element) {
			$ret[$i] = array();
			switch ($element[1]) {
				case "form":
					array_push($ret[$i], array(
										"type"	=>	$element[1],
										"name"	=>	$element[2],
										"action"	=>	$element[3]
									)
								);
					break;
				case "input":
					array_push($ret[$i], array(
										"input"	=>	$element[1],
										"type"	=>	$element[2],
										"name"	=>	$element[3],
										"value"	=>	$element[4],
										"checked"	=>	((($element[2]=="radio"||$element[2]=="checkbox")?true:false)?"true":"false"),
										"disabled"=>	(($element[2]=="radio"||$element[2]=="checkbox")?(($element[6]=="true"||$element[6]=="disabled")?true:false):(($element[5]=="true"||$element[5]=="disabled")?true:false))||(ishidden($element[3],$form))?"true":"false"
									)
								);
					print_r(ishidden($element[3],$form));
					break;
				case "textarea":
					array_push($ret[$i], array(
										"input"	=>	$element[1],
										"name"	=>	$element[2],
										"value"	=>	$element[3],
										"disabled"=>	($element[4]=="true"||$element[4]=="disabled"||ishidden($element[2],$form))?"true":"false"
									)
								);
					break;
				case "select":
					array_push($ret[$i], array(
										"input"	=>	$element[1],
										"name"	=>	$element[2],
										"value"	=>	getoption($element[2],$form),
										"disabled"=>	($element[4]=="true"||$element[4]=="disabled"||ishidden($element[2],$form))?"true":"false"
									)
								);
					break;
				case "button":
					array_push($ret[$i], array(
										"input"	=>	$element[1],
										"name"	=>	$element[2],
										"value"	=>	$element[3],
										"disabled"=>	($element[4]=="true"||$element[4]=="disabled"||ishidden($element[2],$form))?"true":"false"
									)
								);
					break;
			}
			$i++;
		}
	}
	return $ret;
}

Open in new window

what is wrong with this function or perl compatible regular expression that preg_match uses, that it does not return the expected results? 0o
the topmost parent is as follows within https://lmx.leads360.com/web/Login.aspx, as returned by file_get_contents.
<div id="passwordDialog" style="position:absolute;visibility:hidden;height:;width:;" class="dialog"><div id="passwordDialog_HeaderSpan" class="header">
	
            Forgot Password
        
</div><div id="passwordDialog_InnerSpan" class="content password">
	
            <p>Please enter the email address you signed up with and we will send you a new login link.</p>
            <dl>
                <dt>Email:</dt>
                <dd><input name="emailTextBox" type="text" id="emailTextBox" class="bigtextbox" /></dd>
            </dl>
            <div class="buttons submitcancel">
                <a class="submit left" id="submitPasswordRest" onclick="RequestPasswordReset();">Submit</a>
                <a class="cancel right" onclick="passwordDialog.Close();">Close</a>
            </div>
        
</div><div id="passwordDialog_FooterSpan" class="footer">
	
        
</div></div>

Open in new window

if anybody can see why this would not be returning true or the matched text in the function ishidden, even be it as result of it's usage - please let me know.
0
Comment
Question by:intellisource
  • 2
2 Comments
 

Accepted Solution

by:
intellisource earned 0 total points
ID: 36510067
lol nvm - misread a reference earlier to retrieving the style attributes as $parent->$style instead of $parent->getAttribute('style') ;)
0
 

Author Closing Comment

by:intellisource
ID: 36510078
working now! i can get the form elements as an array, choose which ones need to be "displayed" for submission - and then compile the POST str ;)
perserverance is KEY! XD
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question