autosubmit url

Discussion in 'PHP' started by Toddie, Feb 9, 2010.

  1. Toddie

    Toddie New Member

    Joined:
    Jan 9, 2010
    Messages:
    52
    Likes Received:
    2
    Trophy Points:
    0
    I have a simple form here where you add your name and submit it.

    diablouniverse.com/Grab/test.php

    instead of filling out the form i want to make a url that does it for me

    how can i do this?

    an example would be something like this:

    diablouniverse.com/Grab/test.php?&name=Yourname&submit

    but i dont know exactly what i would need to write to make this url work...
     
  2. venami

    venami New Member

    Joined:
    Dec 26, 2008
    Messages:
    195
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    Software Professional
    Location:
    India, Tamil Nadu, Cuddalore
    Home Page:
    http://mvenkatapathy.wordpress.com
    Instead of using the submit button, you can use navigation links(HTML <A> tag) for your purpose. Make the link URL as something like follows:

    Code:
    diablouniverse.com/Grab/target.php?name=Yourname
    Here target.php is the target page where you want to navigate. i.e. When you click a link from test.php, then target.php will be loaded. In target.php, you can get the submitted variable using $_GET['name'].
     
  3. Toddie

    Toddie New Member

    Joined:
    Jan 9, 2010
    Messages:
    52
    Likes Received:
    2
    Trophy Points:
    0
    let me explain further.
    I do not want to have the user type anything into the form.
    I do not even need the form it is just an example for testing.

    I need to have a url that posts data to a txt file.
    I can do it with a form so i know it can be done with just a url.

    I want to eliminate the form.

    the data should be in the url itself so nothing has to be typed into a form.
     
  4. Toddie

    Toddie New Member

    Joined:
    Jan 9, 2010
    Messages:
    52
    Likes Received:
    2
    Trophy Points:
    0
    like for example

    I click this link
    http://www.google.com/#hl=en&source=hp&q=test
    this automatically submits "test" to google

    how can I make a link that automatically submits "test" to my script?
    the script may need to be adjusted to allow this, and I am not sure what I need in my url to actually make it work.

    here is the code to the script
    Code:
    <?php
            // Check if the user submitted this form
            if (isset($_POST["submitwrite"])) {
     echo $_POST['usersname'];
                    // Open the file in write mode
                    $handle = fopen("writetest.txt","a+"); 
                    
                    // If successful
                    if ($handle) {
                            // Write to that handle the username submitted in the form and the date
                            fwrite($handle,$_POST["usersname"] . " - " . date("Y-m-d"));
                            
                            // Close the file
                            fclose($handle);
                    }
            }
    ?>
                    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang = "en" dir="ltr">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>Submit example</title>
    </head>
    <body>
    
    <!-- Notice how the form is submitting to itself -->
    
    <form method="POST" action="test.php" name="form1" id="form1">
    Name: <input type="text" name="usersname"/><br/>
    <input type="submit" value="Write" name="submitwrite"/>
    </form>
    
    </body>
    
    </html>
    
     
  5. loyo

    loyo New Member

    Joined:
    Feb 12, 2010
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://bbs.prog365.com
    you can modify method="POST" to method="GET" , I don't know Whether this is your need?
     
  6. Toddie

    Toddie New Member

    Joined:
    Jan 9, 2010
    Messages:
    52
    Likes Received:
    2
    Trophy Points:
    0
    although venami gave a correct answer, loyo explained it in exact and simple terms.
    I have accomplished the task at hand.

    my only concern is that there is only a 100 character maximum for this function.
    is there a way to increase the character maximum?
     
  7. loyo

    loyo New Member

    Joined:
    Feb 12, 2010
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://bbs.prog365.com
    Is there any limit in your server setting, I have tested your code , it work well.
     
  8. Toddie

    Toddie New Member

    Joined:
    Jan 9, 2010
    Messages:
    52
    Likes Received:
    2
    Trophy Points:
    0
    I also tested but must not have waited long enough for the refresh.
    the variable is passed even though it is over 100 characters long.

    I was misinformed about the limitations of the get variable from this article
    http://www.w3schools.com/php/php_get.asp

    it states

    Note: The get method is not suitable for large variable values; the value cannot exceed 100 characters.
     
  9. loyo

    loyo New Member

    Joined:
    Feb 12, 2010
    Messages:
    36
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://bbs.prog365.com
    yes , the limitations is wrong, I have tested other website to verify it.
     
    Last edited: Mar 4, 2010
  10. Toddie

    Toddie New Member

    Joined:
    Jan 9, 2010
    Messages:
    52
    Likes Received:
    2
    Trophy Points:
    0
    thanks again!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice