Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems

Phone System reconfiguration 11.1.2018 to 26.1.2018 - we are on email but incoming landline not available. Temp number 0797 4 925928
 
Extracting html form input elements

Posted by millisami (millisami), 30 April 2006
This is the html page which is stored in $content variable. (Its only a snippet of the overall html page)
Code:
<input name=".intl" value="us" type="hidden">
   <input name=".bypass" value="" type="hidden">
   <input name=".partner" value="" type="hidden">
   <input name=".u" value="44q6bst25a559" type="hidden">
<input name=".v" value="0" type="hidden">

The following is the code I'm using. I want it to put all the value of attributes, i.e. for this example, value of name and value attributes to $matches array. The above input html contents plus other contents are stored in $content variable.
Code:
preg_match_all('/<input name="([^"]*)" value="([^"]*)" type="hidden" >/', $content, $matches);

And when I do the var_dump($matches), its empty.
Could you please suggest me a way out how to alter the pattern to get the desired result for me.

Thanks in advance.

Posted by admin (Graham Ellis), 1 May 2006
I'm confused as to whether you're setting up a PHP page with variables to be filled in, or trying to extract fields being returned.

If filling in, preg_match only matches - use something like preg_replace.   If extracting, use the $_REQUEST superglobal variable to pick up the values.

As a side thought, it's not good practise to have a lot of hidden fileds in your form - it  makes the pages long and you leave yourself open to users editing the HTML and submitting forged data - for example to changing a price. Have a look at sessions and use a single hidden value and the initial question become irellevant too.

Have a look at the session demo at http://www.wellho.net/resources/ex.php4?item=h115/sc6.php and the preg_replace at the end of it



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho