Results 1 to 4 of 4

Thread: input name fields with html variables and php

  1. #1

    Thread Starter
    Fanatic Member damasterjo's Avatar
    Join Date
    Nov 2005
    Location
    In front of my Comp DirectX7 EXpert
    Posts
    827

    input name fields with html variables and php

    PHP Code:
    <?$i = 0
    $num= 10
      while ($i < $num) {?>
        <input type="submit" name="<?$i?>order1" value="Order This">
        <?$i++?> }
    where then I could call like
    PHP Code:
    if ($iorder1){} 
    ???
    Software languages known:
    Qbasic - TI-Basic - Liberty Basic - Visual Basic 6
    Software API's known:
    Directx 7 and 8
    Internet languages, in the process of learning:
    HTML - JAVASCRIPT - PHP - CSS - MYSQL - AJAX

  2. #2

    Thread Starter
    Fanatic Member damasterjo's Avatar
    Join Date
    Nov 2005
    Location
    In front of my Comp DirectX7 EXpert
    Posts
    827

    Re: input name fields with html variables and php

    name="<?echo $i?>order1"
    ok got how to change name name's now need to learn how to call to it...

    and P.S. I NEED to get firefox, way better!
    Last edited by damasterjo; May 12th, 2006 at 03:15 PM.
    Software languages known:
    Qbasic - TI-Basic - Liberty Basic - Visual Basic 6
    Software API's known:
    Directx 7 and 8
    Internet languages, in the process of learning:
    HTML - JAVASCRIPT - PHP - CSS - MYSQL - AJAX

  3. #3
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: input name fields with html variables and php

    you could use hidden fields
    PHP Code:
    <?$i = 0
    $num= 10
      while ($i < $num) {?>
        <input type="hidden" name="function" value="<?php echo $i?>order1"/>
        <input type="submit" name="<?$i?>order1" value="Order This" />
        <?$i++?> }
    then
    PHP Code:
    if($_POST['function']=="1order1")
    {
        
    //function code
    }
    //.... etc 

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: input name fields with html variables and php

    Give your submit buttons all the same name and each a unique value (which is its caption). When the form is posted you can tell which submit button was pressed just like any other input field.

    PHP Code:
    <div>
      <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
        <p>Which do you prefer?</p>
        <p><input type="submit" name="fsubmit" value="Puppies"></p>
        <p><input type="submit" name="fsubmit" value="Kittens"></p>
      </form>
    </div>
    PHP Code:
    switch ($_POST['fsbumit']) {
      case 
    'Puppies':
        
    # ...
        
    break;
      case 
    'Kittens':
        
    # ...
        
    break;

    If you're using XHTML remember to close the input tags with a />.

Posting Permissions

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



Click Here to Expand Forum to Full Width