Form action = function...possible?

Discussion in 'PHP' started by dwest, Dec 21, 2006.

  1. #1
    Hi,
    I have a PHP page which consists of an upload form. On the same page I have a function that does the uploading.

    How can I trigger the function when the form is submitted?

    Can the form's action parameter be the name of the function on the same page?

    Thanks!
     
    dwest, Dec 21, 2006 IP
  2. Pierre Monteux

    Pierre Monteux Peon

    Messages:
    63
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Let me see if I understand this...you want a function to run when the form is submitted. Your submit button. Is probably something like this.
    <input name="submit" value="Search" type="submit">
    Code (markup):
    In your php form have this.
    
    <?php
    if (isset($_POST['submit']))
    {
    function();
    }
    ?>
    
    Code (markup):
    granted you'll want to do a bit more than that so people can't run the function without submitting the form by some carefully crafted XSS attack. Have fun.
     
    Pierre Monteux, Dec 21, 2006 IP
  3. dwest

    dwest Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ah good point. What could be done instead?
     
    dwest, Dec 21, 2006 IP
  4. dwest

    dwest Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    And thanks for the reply! That does what I need it to do but now you've got me worried about security :confused:
     
    dwest, Dec 21, 2006 IP
  5. Pierre Monteux

    Pierre Monteux Peon

    Messages:
    63
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Have some checks on the data you expect to come in with the form and make sure it is present and valid before running hte function. If the function is harmless, don't worry. Just try to think how it could be manipulated to do something wrong, and block it. Enjoy.
     
    Pierre Monteux, Dec 21, 2006 IP
  6. dwest

    dwest Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Gotcha!
    Thanks for the help!:)
     
    dwest, Dec 21, 2006 IP
  7. weknowtheworld

    weknowtheworld Guest

    Messages:
    306
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    In the from tag write action="". It gets the form submited on same page..
     
    weknowtheworld, Dec 22, 2006 IP