User Tag List

Results 1 to 1 of 1

Thread: Html form multiple inputs with almost same name trick

  1. #1
    Moderator <span style='color: #FF1493'><span class='glow_000000'>Vitrex</span></span>'s Avatar

    Join Date
    Sep 2013
    United Kingdom
    Thanked 134 Times in 94 Posts

    Post Html form multiple inputs with almost same name trick

    Hello all, i know this is the simple "trick" but still usable and sometimes make life easier !
    What it does? for example you need to create 10 inputs with name input_value1 , input_value2 , input_value3 and so on for that use simple php cycle While() for example i need 10 inputs with that names.
    Code will be :

    $i = 0;
    $times = 10;
    While ($i++ < $times) {  
    echo "<input type = 'text' name = 'input_value$i' placeholder = 'input_value$i'/>";
    Now comments :

    $i = 0; - to shut up our error that this undefined variable in cycle.

    $times = 10; - Etner here how much times we want to copy our input and save it to variable

    While ($i++ < $times) { // simple cycle that told server do the code inside to do the same while $i < $times

    echo "<input type = 'text' name = 'input_value$i' placeholder = 'input_value$i'/>"; + Our $i variable will be $i++ or $i +1 every time this code will be executed, that means our $i values gets something like AUTO INCREMENT , and we can just put it in and see the magic ! :D

    } // close cycle, syntax...

    Output will be :

    Why i tell that is usable? Think now for example we are need to calculate something or just fill in values and we have 10 select inputs with 30 option values inside, better to use that trick or write 10 times the same? of course it's easy to copy paste but think about your "Code" style and the file you making, i think this way more clean and faster.
    Hope you enjoy and like this !
    Thank you for your attention in this topic !
    Best Regards, Vitrex.
    Last edited by Vitrex; 09-02-2014 at 09:52 PM.
    Shopper Got a Sticky! 1 year registered Member Level XL Level C
    Raffle Winner Donator Member of Staff
    I won't create anything for you, i can only guide you to right direction.
    Don't forget to read rules before posting.
    Forum Rules
    Need and assistance with your issue? use this section to ask for assistance !
    My Portfolio
    Wanna learn PHP ? check out my One-Page project

  2. The Following 3 Users Say Thank You to Vitrex For This Useful Post:

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts