SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2012
    Location
    Brisbane Australia
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing a form's action field

    Hi everyone
    I was wondering if there is a way to change a form's action field everytime a new user loads the page, e.g if form action="dir/path1/myfile.php" for the first user that loads the page, and form action="dir/path2/myfile.php" for the second user, and form action="dir/path3/myfile.php" for the third user and so on. Then after its gone through say 10 different paths it loops back to the first path again. Any help as always, is greatly appreciated. Cheers

  2. #2
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The easiest way would be just get the number from a file, increment the number, and save it.

    Here is an example:
    PHP Code:
    <?
       $num 
    file_get_contents("file_num.txt");
       if(!
    $num$num 1;
       echo 
    '
    <form method="post" action="dir/path'
    .$num.'/myfile.php">
    <input type="submit" value="Send" name="submit" />
    </form>'
    ;
       if(++
    $num>10$num 1;
       
    $fp fopen("file_num.txt","w");
       
    fwrite($fp,$num);
       
    fclose($fp);
    ?>

  3. #3
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    If you wish the user return to the same form then you have to save the $num for that user.

    Here is an updated example:
    PHP Code:
    <?
       session_start
    ();
       if(
    $_SESSION['file_num']) $num $_SESSION['file_num'];
       else
       {
           
    $num file_get_contents("file_num.txt");
           if(++
    $num>10$num 1;
           
    $fp fopen("file_num.txt","w");
           
    fwrite($fp,$num);
           
    fclose($fp);
           
    $_SESSION['file_num'] = $num;
       }
       echo 
    '
    <form method="post" action="dir/path'
    .$num.'/myfile.php">
    <input type="submit" value="Send" name="submit" />
    </form>'
    ;
    ?>

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2012
    Location
    Brisbane Australia
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx for the reply tom8 but I'm failing to understand this, are you saying I need to create a file named "file_num.txt" and if so, what exactly am I writing in this file. Sorry I'm just a dumb ass aussie trying to teach myself web design. Cheers

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2012
    Location
    Brisbane Australia
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No the user will not be returning to the same form even if they click on refresh a new path will be used, every user will have their own path to "myfile.php". Cheers

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2012
    Location
    Brisbane Australia
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey tom8 your a legend dude!! Once I played with this a little bit and got a grasp on what it was trying to do, and a couple of 404 errors later, everything worked perfectly. Thank you very, very much, you just saved me from another packet of headache tablets. Cheers

  7. #7
    SitePoint Addict tom8's Avatar
    Join Date
    Mar 2012
    Location
    New Jersey
    Posts
    310
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Sorry I could not answer your question since I was sleeping while you were figuring out how my solution would work. Im glad you got it working. As you can see, you no dumb a**

    Were often encountering obstacles from time to time. But with perseverance we will overcome them as you did.

    The solution I suggested was based on changing a single number to the path. But if you need a complete different name for each path then you need something like this:
    PHP Code:
    <?
       $num 
    file_get_contents("file_num.txt");
       if(++
    $num>9$num 0;
       
    $fp fopen("file_num.txt","w");
       
    fwrite($fp,$num);
       
    fclose($fp);

       
    $action = array(
                
    "dira/path01/myfileq.php",
                
    "dirb/path02/myfiler.php",
                
    "dirc/path03/myfiles.php",
                
    "dird/path04/myfilet.php",
                
    "dire/path05/myfileu.php",
                
    "dirf/path06/myfilev.php",
                
    "dirg/path07/myfilew.php",
                
    "dirh/path08/myfilex.php",
                
    "diri/path09/myfiley.php",
                
    "dirj/path10/myfilez.php");

       echo 
    '
    <form method="post" action="'
    .$action[$num].'">
    <input type="submit" value="Send" name="submit" />
    </form>'
    ;
    ?>

  8. #8
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    (or just use sessions and use the session identifier as the path....)
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  9. #9
    SitePoint Enthusiast
    Join Date
    Mar 2012
    Location
    Brisbane Australia
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx guys, I'll keep all this for reference, now that I've got this sorted out, I got a lot of work to catch up on and will, no doubt, will have many more dumb ass questions to ask along the way. You guys and this site rock!!!


Bookmarks

Posting Permissions

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