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
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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., 2024: 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