php to grab html attributes as well as hidden inputs

by 7 replies
9
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
#programming #attributes #grab #hidden #html #inputs #php
  • 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....
  • 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
  • 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.
  • \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.
    • [ 1 ] Thanks
  • 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...
  • Here are the patterns for getting a url from the action as well as getting the hidden input fields from form code.

    action url:
    Grab hidden input fields:
    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
    • [ 1 ] Thanks
  • 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!

Next Topics on Trending Feed