form submit from PHP code

Ask a Question related to PHP Development, Design and Development.

  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. Similar Questions and Discussions

    1. Form does not submit in Mac
      Hi all, I am using the submitForm() on my submit button. I have set the URL to "/Save.aspx" which will get the submitted information and doing...
    2. Need Help With Submit Form
      I have DW 3 and designing my own site. I would like my customer to be able to fill out a form. I know how to create a form, I don't know how to get...
    3. Submit form
      I am creating a control which will upload files. The problem I am having is the button event I have created does not seem to see the files getting...
    4. what in the code makes a .gif a submit button
      How do I make a normal .gif into a submit button that will hold action? ie. <input type='submit' name='Submit' value='Submit'> when I put the src...
    5. Form Field/ Form Submit Problems (probably an easy answer...)
      Hey Everyone.. I have a form that has approximately 7 text fields and 1 checkbox. Generally when this form is submitted(to itself BTW) it works...
  3. #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

  4. #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

  5. #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.thisisnotmysurname@ntlworld.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

  6. #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

  7. #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

  8. #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 = document.getElementById('val1').value;
    if(nm==''){
    misses++;
    document.getElementById('val2').value='Failed to follow instructions
    '+misses+' time(s)';
    alert('You must enter a value');
    }else{
    document.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" <menicoll@mars.ark.com> wrote in message
    news:413b56a9.5267875@news.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

Posting Permissions

  • You may not post new threads
  • You may 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