SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with form

    Hi,
    I want to know how I can pass variables from one page to another, while using a form. I have two forms in a page and depending on which form button is clicked, I want to pass the variables of that form to a different php file. Any idea on how to do this ? I just want to reduce the number of lines in the file. Any idea why this doesn't work and how I can go about accomplishing it ?

    onclick "<?php myFunction($_POST['myField'])? I gives an

    I've tried it but it didn't work. Gives the error: undefined index ....

  2. #2

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the particular HTML and PHP code?

  3. #3
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You didn't understand the concept of PHP. PHP is serverside, it builds the data (for example your HTML markup) which gets sent do the client (browser). PHP does not interact with the browser like client side scripting languages do (e.g. Java Script).

  4. #4
    Non-Member hyperimage's Avatar
    Join Date
    Dec 2003
    Location
    Croatia
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep
    u cant do anything with onClick function onto php variables!
    only with superglobals $_POST, $_GET, $_FILES.
    which build your preformated html tags on your request or storing data into database.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I remember ... php simply generates the html. The thing is that I haven't been in touch with php for about a year now .... its taking time but I'm glad its coming back in small pockets

    So how do I route the processing to a different page ?

  6. #6
    SitePoint Zealot prashidi's Avatar
    Join Date
    Mar 2001
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you not just create two forms and have each one going to a different place?

    Something like:
    HTML Code:
    <form action="[url="http://www.domain.com/1"]http://www.domain.com/1[/url]" method="post"></form>
    and then:

    HTML Code:
    <form action="[url="http://www.domain.com/1"]http://www.domain.com/[/url]2" method="post"></form>

  7. #7
    Non-Member hyperimage's Avatar
    Join Date
    Dec 2003
    Location
    Croatia
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    u even dont need the processing on different page couse u can make it dinamicaly!
    example:
    file hehehe.php (all that stuff into 1 file)
    PHP Code:
    <?php
    include_once( "config.php" );
    ?>
    HTML Code:
    <html><head><title>hehehe</title></head><body>
    <div>
    PHP Code:
    <?php
    if($_POST["go_man")) insert_1();
    else if(
    $_POST["go_girl")) insert_2();
    else if(empty(
    $_POST)){
    draw_me();
    }
    ?>
    HTML Code:
    </div></body></html>
    PHP Code:
    <?php
    function draw_me
    {
    ?>
    HTML Code:
    <form ENCTYPE="multipart/form-data" method="post" action="<?=$_SERVER['PHP_SELF']?>" name="this">
    <input type="text" name="why_that" value="inster something if u want">
    <input type="submit" name="go_man" value="Insert she">
    </form><br><form ENCTYPE="multipart/form-data" method="post" action="<?=$_SERVER['PHP_SELF']?>" name="other">
    <input type="text" name="why_this" value="inster something if u want">
    <input type="submit" name="go_girl" value="Insert me">
    </form>
    PHP Code:
    <?
    }
    function 
    insert_1()
    {
    $why_that $_POST["why_that"];
    if(
    $_POST["why_that"] !=""
      {    
    $ret "Insert into your_table values('', '$why_that')";
          
    $resultat mysql_query($ret);
        
    mysql_close($connect);
    echo 
    "Data sucessfully stored!";
    } else {
    echo 
    "Updating data problems!";  
    }
    }
    function 
    insert_2()
    {
    $why_this $_POST["why_this"];
    if(
    $_POST["why_this"] !=""
      {    
    $ret "Insert into your_table values('', '$why_this')";
          
    $resultat mysql_query($ret);
        
    mysql_close($connect);
    echo 
    "Data sucessfully stored!";
    } else {
    echo 
    "Updating data problems!";  
    }
    }
    ?>
    and u can use this example to output dinamicaly all the html content u want!
    happy coding!

  8. #8
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ^^happy coding

    yeh right ... coding is fun as long as it is working .... and in my case it isn't (whatever the reason)


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
  •