Form Action to /Foldername?

Discussion in 'PHP' started by brianj, May 13, 2009.

  1. #1
    Hi, short question again..

    I have a simple form:

    
    <form id="form" name="form" method="post" action="/">
    <input name="field" id="textfield" value="Foldername" type="text">
    
    PHP:

    How can i make the action going to /Foldername instead /?Field=Foldername




    Thanks in advance,
     
    brianj, May 13, 2009 IP
  2. jlhaslip

    jlhaslip Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try adding a "/" to the folder name.

    
    action="../folder/"
    Code (markup):
    and have an index.php (or index.html) file in that folder handle the request.
     
    jlhaslip, May 13, 2009 IP
  3. brianj

    brianj Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    hm, that doesn't seem to work.. my index.php handles the request, so i still get /?Field=Folder1345


    any more ideas?

    Thx
     
    brianj, May 13, 2009 IP
  4. brianj

    brianj Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    ...anyone?
     
    brianj, May 14, 2009 IP
  5. -[z]-

    -[z]- Active Member

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #5
    In the .htaccess file add the following:

    
    php_flag register_globals on
    RewriteEngine on
    RewriteRule ^folder-(.*)$ index.php?Field=$some_var [QSA]
    
    Code (markup):
    The $some_var should be the same as the one in your php script.

    The will give the effect of sending the form to the folder but you are really sending it a script. This is also more search engine friendly.
     
    -[z]-, May 14, 2009 IP
  6. brianj

    brianj Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #6
    Hey thanks, this is the button code i use:

    
    <form id="form" name="form" method="get" action="../">
    <input type="text" name="Field" value="/" />
    <input type="image" alt="Button" src="/images/button.jpg" />
    PHP:
    The problem i have now:

    /?Field=blablabla&x=0&y=0
    
    Code (markup):
    ...Where does the x=0&y=0 come from??
     
    brianj, May 14, 2009 IP
  7. -[z]-

    -[z]- Active Member

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #7
    Looking at your code you made a mistake in the image button code.
    <input type="image" alt="Button" src="/images/button.jpg" />
    Code (markup):
    is meant to look like this:
    <input type="image" name="submit" alt="Button" src="/images/button.jpg" />
    Code (markup):
    I think that should work... And I'm guessing the x=0&y=0 are because of the code but I'm not 100% on that...

    If that fails just change the code to:

    <input type="submit" name="submit" value="submit" />
    Code (markup):
     
    -[z]-, May 15, 2009 IP
  8. brianj

    brianj Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #8
    Hey thanks.. i changed the type to input, getting this url after submit:

    ht*p://domain.com/?Field=blabla

    So i have to redirect that url to domain.com/blabla in the .htaccess now? How to do that?
     
    brianj, May 15, 2009 IP
  9. -[z]-

    -[z]- Active Member

    Messages:
    51
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #9
    ok create a .htaccess file and put the following in it:

    
    RewriteEngine on
    RewriteBase /
    RewriteRule (.*)$ index.php?Field=$some_var
    
    Code (markup):
    so when you enter
    http://domain.com/?Field=blabla
    Code (markup):
    you should rather use
    http://domain.com/blabla
    Code (markup):
    The .htaccess file hides parts of the true URL and make it look like
    http://domain.com/blabla
    Code (markup):
     
    -[z]-, May 20, 2009 IP
  10. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #10
    (above <HTML><HEAD> etcsection of HTML)
    <?php
    $field = $_POST['field'];

    (write the field to folder with fopen and append)

    I dont know why you want to add a .txt like that to a folder though. Doesnt makemuch sense.
    Look at how to read, write and append to .txt files
    it will let you select the folder and even create a new .txt file with a name you specify

    its basic code, and i aint writing it all here. :D


    ?>


    // In the Body of HTML
    <form id="form" name="form" method="post" action="index.php">
    <input name="field" id="textfield" value="Foldername" type="text">

    //NEW
    <input type="submit" value="Submit this form" onclick="this.form.submit">
     
    ezprint2008, May 21, 2009 IP