rpjd Posted April 27, 2011 Share Posted April 27, 2011 User submits 1 or more refrerences via a form. On the action page I want to check if any id's on the page match any values submitted in $_POST. $Ref = $_POST['Ref']; $source = file_get_contents( 'E:/wamp/www/Project/File.php' ); $document = new DOMDocument; $document->validateOnParse = true; $document->LoadHTML($source); for($i=0; $i<count($Ref); $i++) { $ID = $document->getElementById('$Ref[$i]'); } I have a table on the source page with the same id as a reference contained in $Ref, but getElementById is not seeing/recognsing it. No idea why not. Quote Link to comment https://forums.phpfreaks.com/topic/234866-finding-id-on-page/ Share on other sites More sharing options...
fugix Posted April 27, 2011 Share Posted April 27, 2011 most likely because you are trying to use php with javascript Quote Link to comment https://forums.phpfreaks.com/topic/234866-finding-id-on-page/#findComment-1206971 Share on other sites More sharing options...
rpjd Posted April 27, 2011 Author Share Posted April 27, 2011 How then can I check if an id of a certain value exists on a page that is the same as a submitted form value in $_POST? Quote Link to comment https://forums.phpfreaks.com/topic/234866-finding-id-on-page/#findComment-1206980 Share on other sites More sharing options...
fugix Posted April 27, 2011 Share Posted April 27, 2011 where are the id's on your action page coming from? Quote Link to comment https://forums.phpfreaks.com/topic/234866-finding-id-on-page/#findComment-1206985 Share on other sites More sharing options...
rpjd Posted April 27, 2011 Author Share Posted April 27, 2011 $Ref = $_POST['Ref']; If a table exists on the page whose id is equal to any value in $Ref array, append new row to the table, else create new table whose id is that value. Quote Link to comment https://forums.phpfreaks.com/topic/234866-finding-id-on-page/#findComment-1206991 Share on other sites More sharing options...
fugix Posted April 27, 2011 Share Posted April 27, 2011 where are the id's in the already existing tables coming from though? Quote Link to comment https://forums.phpfreaks.com/topic/234866-finding-id-on-page/#findComment-1207006 Share on other sites More sharing options...
rpjd Posted April 27, 2011 Author Share Posted April 27, 2011 As I just eluded to, if a reference is submitted via the form ($_POST['Ref']) for the first time, then no table exists with that id(value) and a table is created with that id(value). If a reference has been previously submitted, the table does exist and a new row is appended to that table. What I'm trying to do is parse the html on the page and compare the existing table id's if any with submitted references, then call appropriate javascript to create and append the table/row, depending on the comparison result(s). Quote Link to comment https://forums.phpfreaks.com/topic/234866-finding-id-on-page/#findComment-1207027 Share on other sites More sharing options...
fugix Posted April 27, 2011 Share Posted April 27, 2011 okay so you are matching references with references? Quote Link to comment https://forums.phpfreaks.com/topic/234866-finding-id-on-page/#findComment-1207067 Share on other sites More sharing options...
rpjd Posted April 27, 2011 Author Share Posted April 27, 2011 More of less yes, as references are also table id's References can be '1', '12', '11-1'. Quote Link to comment https://forums.phpfreaks.com/topic/234866-finding-id-on-page/#findComment-1207100 Share on other sites More sharing options...
rpjd Posted April 27, 2011 Author Share Posted April 27, 2011 Just for curiousity sakes, I did file_get_contents() on the file, the file_get_html() on the contents. $source = file_get_contents( 'E:/wamp/www/Project/File.php' ); $document = new DOMDocument; $document->validateOnParse = true; $document->file_get_html($source); Fatal error: Call to undefined method DOMDocument::file_get_html() Quote Link to comment https://forums.phpfreaks.com/topic/234866-finding-id-on-page/#findComment-1207230 Share on other sites More sharing options...
rpjd Posted April 29, 2011 Author Share Posted April 29, 2011 I tried file_get_html on the file insteasd on file_get_contents, but I got the same problem, Fatal error: Call to undefined method DOMDocument::file_get_html() Can anyone explain this? Quote Link to comment https://forums.phpfreaks.com/topic/234866-finding-id-on-page/#findComment-1208183 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.