php to grab html attributes as well as hidden inputs

7 replies
Hey all,

I am working on a script that I am a bit stumped with at the moment. Coders block if you will.

Task at hand:
Provide a form for the user to post their auto responder form code in.
PHP to strip everything from the provided string except for the url in the action attribute of the form as well as the hidden inputs to be written to a file.

What I have:
I have the code to replace a marker with the required info but currently the user needs to strip away the excess html.

Sample form code to search:
Code:
<script language="JavaScript">
function checkSub(){
if (document.signup.email.value.indexOf('@', 0) == -1) {
alert("Please fill in your valid Email address.\nYour email should be in the following format: email@address.com")
document.signup.email.focus()
return false}
if (document.signup.fname.value == "") {
alert("Please fill in your First name.")
document.signup.fname.focus()
return false}                          
}</script><form action="http://norabots.com/ar/ar/optin.php" method="post" name="signup" onsubmit="return checkSub()"><input type=hidden name="action" value="addlead"><input type=hidden name="member" value="871"><input type=hidden name="auto" value="5402"><input type=hidden name="thankyou" value=""><table border=0 cellspacing=0 cellpadding=2><tr><td><font size="2" face="arial, verdana">First Name:</font></td><td><input type=text size=20 name="fname"></td></tr><tr><td><font size="2" face="arial, verdana">Email address:</font></td><td><input type=text size=20 name="email"></td></tr><tr><td></td><td align=center><input type="submit" value="Subscribe"></td></tr></table></form>
Stripped down code to be added into file via str_replace:

Code:
http://norabots.com/ar/ar/optin.php

<input type=hidden name="action" value="addlead"><input  type=hidden name="member" value="871"><input type=hidden  name="auto" value="5402"><input type=hidden name="thankyou"  value="">
Hope that helps describe what I am looking for. Thank you in advance for your help.

Sincerely;

Jay
#attributes #grab #hidden #html #inputs #php
  • Profile picture of the author CarloD.
    What are you trying to do? build a form so people can send you there auto responder code? then you strip everything but the action?

    Why not just get them to submit their action?

    Maybe I don't follow....
    Signature

    {{ DiscussionBoard.errors[2046625].message }}
  • Profile picture of the author theIMgeek
    I was just doing some work yesterday on extracting bits from HTML code.

    The key function is PHP: preg_match_all - Manual

    You can use regular expressions to pick out just the stuff you want. If you've never worked with regular expressions before, prepare to get frustrated. If you have some experience with regular expressions... well... still prepare to be frustrated! (I at least always find them a bit a trial-and-error process)

    -Ryan
    Signature
    FREE WSO: Protect and Automatically Deliver Your Digital Products

    Ask the Internet Marketing Geek
    <-- Happy to help with technical challenges
    MiniSiteMaker.org <-- Free software to make your mini-sites fast and easy
    {{ DiscussionBoard.errors[2046632].message }}
  • Profile picture of the author jaybaker
    Thank you both for your input...
    Yeah the idea is that instead of them hunting for their action value then hunting for the hidden input fields I want to make it as simple as possible for them by just javing them post their whole ar code in. Im designing this for people that DO NOT have ANY experience with html or at least the bare minimum.
    Signature

    Do you want to make successes or excuses? Success? Alright then... See what's in store for you....
    - The AC Assassin

    {{ DiscussionBoard.errors[2046937].message }}
  • Profile picture of the author Manfred Ekblad
    \b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))

    dont mind the smiley...

    thats the regexp you need to get the URL (there are many other ways to write the regexp, this one works)

    just keep learning regexps and you'll be able to get the hidden input tags as well.

    here is an online tool to test and learn regular expressions.
    {{ DiscussionBoard.errors[2047205].message }}
  • Profile picture of the author jaybaker
    Thanks man I have got the url now all I need is to grab the input fields... Thanks for the tool will def use it...
    Signature

    Do you want to make successes or excuses? Success? Alright then... See what's in store for you....
    - The AC Assassin

    {{ DiscussionBoard.errors[2047403].message }}
  • Profile picture of the author jaybaker
    Here are the patterns for getting a url from the action as well as getting the hidden input fields from form code.

    action url:
    /action=["\']?([^"\']?.*(php|asp|pl))["\']?/i
    /action= denotes we want to find it and the subsequent url.
    ["\'] means we want to optionally look for double or single quotes
    ? look for any character
    ( start grouping
    [^"\'] means we don't want to look for any additional quotes
    ?.* look for any other part of the url
    (php|asp|pl)) for grabbing the file extension stating to look for pearl php and asp
    ?/i is for setting things up to be case insensitive
    Grab hidden input fields:
    /<input.+?type=hidden.+?[{/?}|{s?}]?>/i
    <input starts tag
    .+? looks for a whitespace
    type=hidden and am not quite sure of what the rest means as I am still learning regex.
    My point for posting this is to at least save someone the trouble of finding the regex for certain things in regards to dealing with xhtml.

    J
    Signature

    Do you want to make successes or excuses? Success? Alright then... See what's in store for you....
    - The AC Assassin

    {{ DiscussionBoard.errors[2048952].message }}
  • Profile picture of the author Manfred Ekblad
    Great stuff!

    I wish everyone who ever asked for advice in this forum and then later solved their problem would post back the final solution just as you did. Thumbs up!
    {{ DiscussionBoard.errors[2050175].message }}

Trending Topics