SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 38 of 38
  1. #26
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    ... and we're back! Hello SPers ...

    You have no submit button.

    Code:
    <form etc ...>
    
    // your form elements
    
    <input type=submit />
    </form>
    Some personal preferences of mine:
    PHP Code:
    $environ=$_POST["env"]; 
    I always use single quotes on stringed array keys, you used single and double in your example code, that will end up in confusion. Pick one, stick to it.
    PHP Code:
    $environ=$_POST['env']; 
    and...

    PHP Code:
    <form method="post" action="<?php echo $_SERVER['$PHP_SELF'];?>">
    I always use CAPS for form method declarations -- jumps off the page at me, and if the form submits to itself, I leave the action blank.
    PHP Code:
    <form method="POST" action=""

  2. #27
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    22
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi thanks for your reply. I was actually trying to do this without a submit button, in such a way that selecting the filter option from the dropdown box will automatically refresh the page with the queries I want.

    I found out from forums that the parameter: "onchange="document.getElementById("env").submit();">", added with the <select> will do the trick.

    But when I select an option from the drop down box, the page stays still. This is how the form and select statements look like, and this dropdown is in a table cell:

    <td>
    <form method="post" id="env" action="<?php echo $_SERVER[PHP_SELF];?>" >
    <select name="name" onchange="document.getElementById("env").submit();">
    <option value="all">All</option>
    <option value="Windows">Windows</option>
    <option value="Win 2008">Win 2008</option>
    <option value="Win 7">Win 7</option>
    <option value="Win Vista">Win Vista</option>
    <option value ="Linux">Linux</option>
    <option value = "Win 7/Linux">Win 7/Linux</option>
    </select>
    </form>
    </td>


    And for trial purposes, I want to see if the option that I selected is being echoed as:

    <?php
    if(isset($_POST["name"]))
    {
    echo $_POST["name"];
    }
    ?>

    But the page remains still once I select an option. Can you let me know what I am doing wrong here?

    Also this page is an authenticated page, like it appears after user logs in with their username/pwd. Just letting you know this, so that you can have a better picture of this page. Please let me know if you have any questions.

  3. #28
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    22
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Actually I think I made mistake in calling the javascript function. So I declared the function as:

    function formSubmit()
    {
    document.getElementById("report_filter").submit();
    }

    and called this in the "onchange" event as:

    <form method="post" id="report_filter" action="<?php echo $_SERVER[PHP_SELF]?>" >
    <select name="try" onchange="formSubmit();">
    <option value="all">All</option>
    <option value="Windows">Windows</option>
    <option value="Win 2008">Win 2008</option>
    <option value="Win 7">Win 7</option>
    <option value="Win Vista">Win Vista</option>
    <option value ="Linux">Linux</option>
    <option value = "Win 7/Linux">Win 7/Linux</option>
    </select>
    </form>

    The page reloads when I select an option, but a blank white page comes up after this. Please let me know if you have any idea about this.

  4. #29
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    So you are convinced your JS is not at fault, so put this at the very top of the page then.
    PHP Code:
    <?php
    var_dump
    ($_POST);
    ?>

  5. #30
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    22
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Actually I am working on this page along with other team mates and this is an additional feature I am trying to implement. This page will appear after user logs in and selects a type of form he wants to view.

    So I think because of that when I gave the "var_dump($_POST);" I got:

    "array(2) { ["env_select"]=> string(8) "centrify" ["view"]=> string(4) "View" }"

    So I tried "var_dump($_POST["env"]);" and I saw "NULL" was returned. So there is a problem with the form returning the value here. Please let me know your thoughts

  6. #31
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by learner101
    So I tried "var_dump($_POST["env"]);" and I saw "NULL" was returned.
    You've got several things wrong here I think.

    id attributes are only used on the DOM, name attribute is passed via html to PHP.

    form names are not passed to PHP.

    PHP Code:
    <?php
    var_dump 
    ($_POST);
    ?>
    <form id=myform name=myform method=POST action="">
    <input type=text id=mytext name=mytext value =test>
    <input type=submit name=mysubmit>
    </form>
    In that example mytext is passed along, but myform is not.

    If using JS to bundle up the form elements you will have to shovel the id into a name attribute and pass it on, or pass it on some other way.

    Or use a hidden form element read this.

  7. #32
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    22
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I am not sure what you said there. But I will tell you the thing I tried recently.

    I used the code which I have been trying to use in the page I am working on, in a separate PHP page and I ran it. It is the same code I have been trying so far and it is as follows:


    <script>
    function formSubmit()
    {
    document.getElementById("report_filter").submit();
    }
    </script>

    <form method="POST" id="report_filter" action="" >
    <select name="try" onchange="formSubmit();">
    <option value="all">All</option>
    <option value="Windows">Windows</option>
    <option value="Win 2008">Win 2008</option>
    <option value="Win 7">Win 7</option>
    <option value="Win Vista">Win Vista</option>
    <option value ="Linux">Linux</option>
    <option value = "Win 7/Linux">Win 7/Linux</option>
    </select>
    </form>

    <?php

    if(!(isset($_POST["try"])))
    {
    echo "none";
    }
    else
    echo $_POST["try"];

    ?>



    This created a dropdown box with all the elements listed above, and when I select one of the options I see that it is being echoed. Like, initially "none" is echoed, and then the option being selected in the dropdown box such as "Windows", "Windows 2007" or whatever is being echoed.

    Here I am not posting the form name, but the "<select>" menu's name "try" only as you said, and I see that the option being selected is echoed as expected.

    The same code is not working in the php page that I am currently working on. Please let me know if you need any more information

  8. #33
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The same code is not working in the php page that I am currently working on. Please let me know if you need any more information
    So how is the PHP page different then?

  9. #34
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    22
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    So how is the PHP page different then?
    I am not quite sure about that. I am still new to PHP programming and so probably I am missing to see some point here. If it gives out some form of error then I can debug, but seeing just a white screen is not helping me at all.

    This PHP page I am working on, will appear after the user logs in and selects a company name from a dropdown menu. This is being worked on by other batchmates so I am not entirely familiar with the code there. But still I think this dropdown code must work since its working independently.

    It will be really helpful if you can help me debug this. Please let me know if you need any more information about this

  10. #35
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    My immediate guess is that either a header("Location: xyz.php") is causing a magic relocate somewhere in the code (to a blank page), or the page that is being served up does not have error reporting turned on -- or maybe even both of the above.

  11. #36
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    22
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Just one more info for you. I asked the other batchmates here and they say there are some Session variables being used in this PHP page, and the session is started every time the page is loaded. I also see that there is some code like "session_start();" and some variables are also passed thru the session like "$_SESSION['username']" etc. Please let me know if there is something related to this session to the filter I am trying to build.

  12. #37
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    22
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    When I commented out the code containing the "session_start();" and any other code getting value from session, I see that when I select the dropdown option, the option is echoed as I have been trying. SO I think this has got something to do with the "session". Maybe I need to look more into this, but if you know something about this that might help me, then please let me know.

  13. #38
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    22
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    When I goto this page straightaway without logging in, and by commenting out the session commands like "session_start()" and all, the page can echo the required string, based upon the selection in the dropdown box.

    So can you tell me how to stop this issue, or if you think there is something wrong with the way I found out the cause of the issue, then please notify that as well. Please let me know if you need more details.


Tags for this Thread

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
  •