SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Zealot annimal's Avatar
    Join Date
    May 2004
    Location
    london
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question using functions in submit form

    Hay all i got a function that i would like to be submited by a form filed button im not sure on how the sytax should look.

    This is the function i wish to send

    PHP Code:
       function sendChatMessage($message) { 
       
    sendCommand"<" $this->getNick ">"$message); 

    and this is what i want to use to send it

    Code:
      <form name="SNDTXT" method="GET" action="">
      <label for="textfield">Text</label>
      <input name="textfield" type="text" id="textfield" value="usertxt">
      <label for="Submit"></label>
      <label for="label1"></label>
      <input type="submit" onClick="">
      </form>
    any help would be apretiated as im new to usning PHP functions!

    P.S Great forum

  2. #2
    SitePoint Addict yjanse's Avatar
    Join Date
    Apr 2004
    Location
    The Netherlands
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am amazingly short on time, so a few pointers.
    Change method to POST and action to "action.php".
    Name the form input items. (I will fix your HTML here)
    Then use action.php to get the $_POST['tfUser'] value for example.

    Code:
    <form name="SNDTXT" method="POST" action="action.php">
      <label>
      <input name="tfUser" type="text" id="tfUser" value="">Text</label>
    
      <input type="submit" name="btnSubmit" value="Send">
      </form>
    Dont have time to post more, there are 1000's here who can help you.

  3. #3
    SitePoint Zealot annimal's Avatar
    Join Date
    May 2004
    Location
    london
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx my form is ready to send information there is still a slight problem with sending the

    PHP Code:
        function sendChatMessage($message) { 
       
    sendCommand"<" $this->getNick ">"$message); 

    $message thats going to be but in the tfUser field i know there is a way to do this but for the life of me cant get it right grrrrr lol

  4. #4
    SitePoint Guru
    Join Date
    Feb 2004
    Location
    Oregon
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    huh? you are trying to send $message to the function after they hit submit? then a few things. one is already pointed out to you. add a action and add POST. then you need to add the function call when the form gets submited on another page. so in the action you have the page you send to then on that page you have this

    action.php
    PHP Code:
    if($_POST['textfield']){
    // run function
    sendChatMessage($_POST['textfield']);

    Last edited by Sahajin; May 27, 2004 at 10:15.
    success is not by chance, it is by choice.

  5. #5
    SitePoint Zealot annimal's Avatar
    Join Date
    May 2004
    Location
    london
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is true yea i forget to mention in this post that the function i am trying to send is from a direct connect phpclient i.e PHPDC i have the full protocol and login handshake but im missing a few functions
    PHP Code:
        function sendChatMessage($message) { 
       
    sendCommand"<" $this->getNick ">"$message); 

    is planned to be sent directly to the hub/room that i am in via a send button i realy just need to put the above function in a submit form to send text to the direct connect hub/room

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    Annimal,

    As pointed out above (TWICE), PHP is a hypertext PRE processor. In other words, you've got to use other code (action.php was suggested) to send your message as it canNOT be sent as you're leaving the page -- use JavaScript for that.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


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
  •