Professional Web Applications Themes

form submit from PHP code - PHP Development

I am new to PHP, but am an experienced programmer. I am having trouble understanding how to transfer control from one php/html script to another. I know how to let the user do it: with links, and HTML form submits, but how do I do it from PHP code? e.g. if I am in script A.php , and I want script B.php to fire up just as if it had been activated through a form submit, with POST variables set, how do I do it? Matthew Nicoll...

  1. #1

    Default form submit from PHP code

    I am new to PHP, but am an experienced programmer.
    I am having trouble understanding how to
    transfer control from one php/html script
    to another. I know how to let the user do it:
    with links, and HTML form submits, but how do I
    do it from PHP code?

    e.g. if I am in script A.php , and I want script B.php to
    fire up just as if it had been activated through a
    form submit, with POST variables set, how do I
    do it?

    Matthew Nicoll


    Matthew Nicoll Guest

  2. #2

    Default Re: form submit from PHP code

    Matthew Nicoll wrote:
    > I am new to PHP, but am an experienced programmer.
    > I am having trouble understanding how to
    > transfer control from one php/html script
    > to another. I know how to let the user do it:
    > with links, and HTML form submits, but how do I
    > do it from PHP code?
    >
    > e.g. if I am in script A.php , and I want script B.php to
    > fire up just as if it had been activated through a
    > form submit, with POST variables set, how do I
    > do it?
    >
    Very basic question for which the answer can be found on php.net:

    A.php:

    <html>
    <body>
    <form method="post" action="B.php">
    Name:
    <input type="text" name="name" />
    <input type="submit" />
    </form>
    </body>
    </html>


    B.php:

    <?
    if (isset($_POST['name'])) {
    print "Hello {$_POST['name']}";
    }
    ?>


    JW



    Janwillem Borleffs Guest

  3. #3

    Default Re: form submit from PHP code

    Matthew Nicoll spilled the following:
    >
    > e.g. if I am in script A.php , and I want script B.php to
    > fire up just as if it had been activated through a
    > form submit, with POST variables set, how do I
    > do it?
    >
    Short answer: you can't - PHP is a server-side language.

    Longer answer: If you mean you want to simulate a submit of a form to
    scriptB, then it's fairly easy to do with the file(...) function (assuming
    URL wrappers are enabled) e.g.
    $output=get("http://server.name.com/scriptB.php?param1=something&param2=somethingelse" );

    It's a bit more tricky to do a POST (AFAIK this is not supported directly by
    PHP so you need to roll your own HTTP protocol handler and open and close
    sockets from your PHP code. Acutally it's not that hard (even I can do it).

    HTH

    C.

    Colin McKinnon Guest

  4. #4

    Default Re: form submit from PHP code

    Thanks Colin.
    I was hoping I could mess with the values of <input type="hidden"...>
    form variables after the submit button is clicked and before the form
    action was invoked, by having the form action invoke an intermediary
    php script. I don't fancy diving into HTTP protocol handlers just
    now!

    .... Matthew


    On Sun, 05 Sep 2004 20:01:03 GMT, Colin McKinnon
    <colin.thisisnotmysurnamentlworld.deletemeunlessU RaBot.com> wrote:
    >Matthew Nicoll spilled the following:
    >
    >>
    >> e.g. if I am in script A.php , and I want script B.php to
    >> fire up just as if it had been activated through a
    >> form submit, with POST variables set, how do I
    >> do it?
    >>
    >
    >Short answer: you can't - PHP is a server-side language.
    >
    >Longer answer: If you mean you want to simulate a submit of a form to
    >scriptB, then it's fairly easy to do with the file(...) function (assuming
    >URL wrappers are enabled) e.g.
    >$output=get("http://server.name.com/scriptB.php?param1=something&param2=somethingelse" );
    >
    >It's a bit more tricky to do a POST (AFAIK this is not supported directly by
    >PHP so you need to roll your own HTTP protocol handler and open and close
    >sockets from your PHP code. Acutally it's not that hard (even I can do it).
    >
    >HTH
    >
    >C.
    >
    Matthew Nicoll Guest

  5. #5

    Default Re: form submit from PHP code

    Hello,

    On 09/05/2004 06:12 PM, Matthew Nicoll wrote:
    > I was hoping I could mess with the values of <input type="hidden"...>
    > form variables after the submit button is clicked and before the form
    > action was invoked, by having the form action invoke an intermediary
    > php script. I don't fancy diving into HTTP protocol handlers just
    > now!
    If you want to alter the submitted form values, just change the $_POST
    array values in the beggining of the script you want to alter.

    If you want to alter the values and submit them another page, you may
    want to try this HTTP client class. It lets you emulate form post
    submission at will, including uploading files if necessary:

    [url]http://www.phpclasses.org/httpclient[/url]


    --

    Regards,
    Manuel Lemos

    PHP Classes - Free ready to use OOP components written in PHP
    [url]http://www.phpclasses.org/[/url]

    PHP Reviews - Reviews of PHP books and other products
    [url]http://www.phpclasses.org/reviews/[/url]

    Metastorage - Data object relational mapping layer generator
    [url]http://www.meta-language.net/metastorage.html[/url]
    Manuel Lemos Guest

  6. #6

    Default Re: form submit from PHP code

    Matthew Nicoll wrote:
    > Thanks Colin.
    > I was hoping I could mess with the values of <input type="hidden"...>
    > form variables after the submit button is clicked and before the form
    > action was invoked, by having the form action invoke an intermediary
    > php script. I don't fancy diving into HTTP protocol handlers just
    > now!
    >
    Even if you would use the HTTP protocol handlers, all that you get is the
    response from the other page on the page that applies them.

    If you only want to change form values before submission, you could use
    javascript or apply session vars to store (some keys/values of) the $_POST
    array and unwrap them on the other page.


    JW



    Janwillem Borleffs Guest

  7. #7

    Default Re: form submit from PHP code

    Javascript is the way to go for this, I use it all the time on our Intranet
    for form verification and to update hidden variables in a form.
    The submitform script can be fired by any number of methods: onload,
    onunload, onclick, onmouseover, onmousedown, onmouseout, etc.

    <SCRIPT language="JavaScript">
    var misses=0;
    function submitform()
    {
    var nm = doent.getElementById('val1').value;
    if(nm==''){
    misses++;
    doent.getElementById('val2').value='Failed to follow instructions
    '+misses+' time(s)';
    alert('You must enter a value');
    }else{
    doent.myform.submit();
    }
    }
    </SCRIPT>

    <form name=myform method=post action=postit.php>
    <input type=text id=val name=val1 size=50><br>
    <input type=text id=val name=val2 size=50>
    </form>
    <input type=button onClick="submitform();" value="submit">



    The submit button can be placed anywhere on the page and does not even have
    to be a button, it could be text or an image, or just an area on the page
    defined by a span or div. I code for IE on our intranet so if this does not
    work in all browsers then you'll have to fix it. :)

    "Matthew Nicoll" <menicollmars.ark.com> wrote in message
    news:413b56a9.5267875news.ark.com...
    >I am new to PHP, but am an experienced programmer.
    > I am having trouble understanding how to
    > transfer control from one php/html script
    > to another. I know how to let the user do it:
    > with links, and HTML form submits, but how do I
    > do it from PHP code?
    >
    > e.g. if I am in script A.php , and I want script B.php to
    > fire up just as if it had been activated through a
    > form submit, with POST variables set, how do I
    > do it?
    >
    > Matthew Nicoll
    >
    >

    Arg Guest

  8. #8

    Default Re: form submit from PHP code

    could you please share those php submit files... i'm not understanding.. if you help me what files are need for submit button... i wants to make a online course form..
    aricknicho@gmail.com Guest

Similar Threads

  1. Form does not submit in Mac
    By ContactJakku@gmail.com in forum Adobe Acrobat Macintosh
    Replies: 0
    Last Post: January 29th, 10:42 PM
  2. Need Help With Submit Form
    By NewtoDesign in forum Macromedia Dynamic HTML
    Replies: 1
    Last Post: November 10th, 10:42 AM
  3. what in the code makes a .gif a submit button
    By AWZ in forum Dreamweaver AppDev
    Replies: 1
    Last Post: April 16th, 05:46 PM
  4. Replies: 4
    Last Post: September 24th, 12:34 PM
  5. form without submit
    By doug777 in forum Macromedia Dreamweaver
    Replies: 0
    Last Post: July 28th, 02:32 AM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139