Can PHP control a form value directly

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David

    Can PHP control a form value directly

    Ok. Can PHP control a form value directly? Eg. like the javascript
    "document.Form1 .text01.value = "Y"". Eg. allow me to put a value into
    a form text field on page load. Either I missed this in my PHP book
    or the function does not exist.

    The only way I have seen is to put code in the value part of the input
    item, see below.

    Thanks



    <input type="text" value = "<? echo sprintf("%01.2f ",
    $TotalCost);?>"/>
  • Oli Filth

    #2
    Re: Can PHP control a form value directly

    David said the following on 05/09/2005 23:06:[color=blue]
    > Ok. Can PHP control a form value directly? Eg. like the javascript
    > "document.Form1 .text01.value = "Y"". Eg. allow me to put a value into
    > a form text field on page load. Either I missed this in my PHP book
    > or the function does not exist.[/color]

    PHP is server-side, so it has no control of the form, other than the
    HTML/Javascript/etc. that is sent to the browser.
    [color=blue]
    >
    > The only way I have seen is to put code in the value part of the input
    > item, see below.
    >
    >
    > <input type="text" value = "<? echo sprintf("%01.2f ",
    > $TotalCost);?>"/>[/color]

    So this (and variants) are the only way of doing this.

    --
    Oli

    Comment

    • Malcolm Dew-Jones

      #3
      Re: Can PHP control a form value directly

      David (martindb@sbcgl obal.net) wrote:
      : Ok. Can PHP control a form value directly? Eg. like the javascript
      : "document.Form1 .text01.value = "Y"". Eg. allow me to put a value into
      : a form text field on page load. Either I missed this in my PHP book
      : or the function does not exist.

      : The only way I have seen is to put code in the value part of the input
      : item, see below.

      : Thanks



      : <input type="text" value = "<? echo sprintf("%01.2f ",
      : $TotalCost);?>"/>

      Normally php is simply generating text to send to the browser, so yes,
      normally the above is exactly what you have to do (give or take the choice
      of php commands to use).

      If you use a template system to generate your output then there may be a
      technique provided by the template system to set a value. In that case
      you create and populate your template and then send the template, as a
      long text string, to the browser. Whether the template control language
      looks similarly to Javascript will depend on the template system.

      One special case of a template system is to use something like an xml
      builder library. Your php program can build an xml data structure in
      memory. That DOM can be manipulated all you like. When it is ready you
      send a stringified version of the DOM to the brower.

      In no case, however, you are ever manipulating the value on the browser
      like javascript would. All you can ever do is prepare a finished version
      of the html text (including what ever values you wish) and then you send
      that finished text to the browser.

      Well actually, if you run a Java applet on the browser then the server may
      have the ability to communicate directly with the values being displayed,
      but that is a whole other kettle of coffee, and I have no idea what (if
      any) php libraries would help you do that. (Not to mention that you would
      probably need to write your own custom Java applet as well). I mention
      this just for completeness, it is not something most web programmers will
      ever do.

      --

      This programmer available for rent.

      Comment

      • Steve

        #4
        Re: Can PHP control a form value directly

        No.

        That being said you could always remote with Flash or Processing or a
        POJA.

        Comment

        • David

          #5
          Re: Can PHP control a form value directly

          Thanks for the info. I guess I have been having too much fun with
          ASP.net, which allows direct asp forms access.

          Need to shift back to the php mindset!


          On Mon, 05 Sep 2005 22:45:53 GMT, Oli Filth <catch@olifilth .co.uk>
          wrote:
          [color=blue]
          >David said the following on 05/09/2005 23:06:[color=green]
          >> Ok. Can PHP control a form value directly? Eg. like the javascript
          >> "document.Form1 .text01.value = "Y"". Eg. allow me to put a value into
          >> a form text field on page load. Either I missed this in my PHP book
          >> or the function does not exist.[/color]
          >[/color]

          Comment

          • Geoff Berrow

            #6
            Re: Can PHP control a form value directly

            I noticed that Message-ID: <j641i11kl5p888 0s2d7iipkhbd86f ckunu@4ax.com>
            from David contained the following:
            [color=blue]
            >Thanks for the info. I guess I have been having too much fun with
            >ASP.net, which allows direct asp forms access.[/color]

            Yebbut, it uses Javascript to do it!

            --
            Geoff Berrow (put thecat out to email)
            It's only Usenet, no one dies.
            My opinions, not the committee's, mine.
            Simple RFDs http://www.ckdog.co.uk/rfdmaker/

            Comment

            • Tim Roberts

              #7
              Re: Can PHP control a form value directly

              Geoff Berrow <blthecat@ckdog .co.uk> wrote:
              [color=blue]
              >I noticed that Message-ID: <j641i11kl5p888 0s2d7iipkhbd86f ckunu@4ax.com>
              >from David contained the following:
              >[color=green]
              >>Thanks for the info. I guess I have been having too much fun with
              >>ASP.net, which allows direct asp forms access.[/color]
              >
              >Yebbut, it uses Javascript to do it![/color]

              Exactly. I've sometimes wondered how many ASP.NET programmers realize that
              their simple forms code is generating hordes of Javascript, and that many
              seemingly simple user interface actions require rather expensive round
              trips.
              --
              - Tim Roberts, timr@probo.com
              Providenza & Boekelheide, Inc.

              Comment

              Working...