Follow us on Twitter!
I'd prefer to die standing, than to live on my knees - Che Guevara
Sunday, April 20, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 28
Guests Online: 27
Members Online: 1

Registered Members: 82843
Newest Member: hx47
Latest Articles
View Thread

HellBound Hackers | Computer General | Programming

Author

php dynamic input forms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-09-08 12:04
Sorry guys. This may be a stupid question but Im making a form which needs to be dynamic and when the user selects a number (ie. 10) it will produce 10 more input fields.

I need to do this in PHP preferably. What is the best way of doing this.
Can someone please post a tut or a page where i can learn from....?

Thanks.
Author

RE: php dynamic input forms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-09-08 12:08
http://www.w3schools.com/php/default.asp


Author

RE: php dynamic input forms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-09-08 12:10
Yeah thanks. Ive looked there. It doesnt explain how to make things dynamic. Or if it does I couldnt find it.
Author

RE: php dynamic input forms

clone4
Member



Posts: 586
Location: He is back and he's bad!
Joined: 25.11.07
Rank:
Mad User
Posted on 03-09-08 12:20
I won't bother writing the whole code, but how about switch statement, where for each value, you echo appropriate input fields:
switch ($input_field){
case 1;
echo "<form>....</form>";
break;
....
}



[img][/img]img164.imageshack.us/img164/5713/perlvl0.jpg

clone4.freehostia.com/ubuntu_3.png
spyware - "They see me trollin'..."
<yaragn> ever seen that movie? The Matrix?
<yaragn> with those green lines of flying text?
<yaragn> *THAT'S* Perl

clone_4@hotmail.com
Author

RE: php dynamic input forms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-09-08 12:22
ill give it a go. I think it should work.

Much appriciated.
Author

RE: php dynamic input forms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-09-08 12:35
grr i cant get anything to work.
Any more help on the code please?
Author

RE: php dynamic input forms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-09-08 12:48
what do you mean, do you want it to make the numbers appear on screen without posting? IF so look at ajax.


Author

RE: php dynamic input forms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-09-08 12:54
Basically something liek this:
<SELECT>
<option>Select one</option>
<option>1</option>
<option>2</option>
....

Then which ever number they chose I want that many input fields to come up ie. if they chose 2 it will echo "<input type="text" name="whatever">";
twice. or soemthing.
Author

RE: php dynamic input forms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-09-08 12:56
Yes i understand that , but do you want the page to be posted or not?


Author

RE: php dynamic input forms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-09-08 13:08
preferably not.
Author

RE: php dynamic input forms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-09-08 13:19
Ok, then look at onChange events and ajax


Author

RE: php dynamic input forms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-09-08 13:22
Code

<body>
<form action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<?php
 if (isset($_POST['inputnumber'))
 {
   $count = htmlentities($_POST['inputnumber']);
   if (is_numeric($count))
   {
     for ($x = 0; $x < $count; $x++)
     {
       echo 'Input #'.$x.':  <input type="text" name="input'.$x.'" /><br />';
     }
   }
  }
  else
  {
    echo '<input type="text" name="inputnumber" /><br />';
  }
?>
<input type="submit" value="Submit" />
</form>
</body>




Of course, you'll want to do more to protect your inputs than just "htmlentities()"... I just put that there as a placeholder. Also, you'll need to handle your own form submissions for after they choose how many inputs. Just had to write some code for it since no one seemed to hit on the most efficient way. Good luck.

You... may find it a bit troublesome to update a form with additional fields using JS if you intend to POST it normally with PHP. Also, if you don't know PHP that well (or at all), there's no reason for you to try AJAX just yet. My advice would be to just stick with PHP for now and don't sweat the postback.




Edited by on 03-09-08 13:27
Author

RE: php dynamic input forms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-09-08 14:17
Thanks man.
I'm glad you could help me.

Thanks a lot =]]
Author

RE: php dynamic input forms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-09-08 14:48
No problem... couldn't stand to see so many wrong answers in the thread. There's still a lot more work to be done with making it actually DO something. Just wanted to illustrate the concept.


Author

RE: php dynamic input forms

crashbird
Member



Posts: 83
Location: India
Joined: 15.06.07
Rank:
Newbie
Posted on 03-09-08 17:12
hey.. wouldn't that code.. require him to post the page..
I guess if you want it to be dynamic.. learn a little of ajax..
that should solve your problem..

And i am too lazy to code that for you..
I hope i helped...


www.hellboundhackers.org/sig/r/20526.png
elijah981 elijah981
Author

RE: php dynamic input forms


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 03-09-08 17:55
crashbird wrote:
hey.. wouldn't that code.. require him to post the page..
I guess if you want it to be dynamic.. learn a little of ajax..
that should solve your problem..

Zephyr_Pure wrote:
You... may find it a bit troublesome to update a form with additional fields using JS if you intend to POST it normally with PHP. Also, if you don't know PHP that well (or at all), there's no reason for you to try AJAX just yet. My advice would be to just stick with PHP for now and don't sweat the postback.


Read my post next time before you make obvious statements like that.


And i am too lazy to code that for you..
I hope i helped...


Can't imagine he was asking for you to code it for him... he was asking for advice. Only reason I put code in this thread is because the people before me had the concept completely wrong.

We can tell you're lazy... it was reflected in your post. So, no, you didn't help... at all. Assface.