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
 
20.9.2014 - We have just updated our course layouts and descriptions and added our 2015 schedule.

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., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho