struggling with $_POST

Discussion in 'PHP' started by marcnyc, Jun 16, 2009.

  1. #1
    Hello, I am having a hard time getting a value sent to via POST.

    I have a PHP code which outputs this HTML:


    Please select your preferred ADMIN AREA language:
    	<!-- beginning of admin language selector drop down menu //-->
    		<form action="/?p=menuedit" method="post">
    			<script type="text/javascript">var url_full = "/?p=menuedit";</script>
    			<img src="/images/flags_iso/24/us.png" style="position:relative;top:7px;" />
    			<select name="l_admin" OnChange="this.form.submit();window.location.href=url_full;">
    				<option value="en" selected>English</option>
    				<option value="it">Italiano</option>
    			</select>
    		</form>
    	<!-- end of admin language selector drop down menu //-->
    
    HTML:
    I also tried using just <form action="" method="post"> or even just <form method="post">.

    This form resides on the page /?p=menuedit (I am actually generating that part of the HTML with this PHP):

    echo '<form action="/?'.$_SERVER['QUERY_STRING'].'" method="post">'; 
    
    PHP:
    At the top of the page, for the sake of testing it, I put:

    echo $_POST['l_admin']; 
    PHP:
    But every time I submit the form I get:

    Notice: Undefined index: l_admin in /home2/memory/public_html/globals.inc.php on line 26
    
    Code (markup):
    In other words, somehow it seems like my form is not submitting the post values... Can somebody help me figure out what I am doing wrong?

    Thanks a lot
     
    marcnyc, Jun 16, 2009 IP
  2. Vbot

    Vbot Peon

    Messages:
    107
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    remove these 2 lines from your code and it will work.

    1. <script type="text/javascript">var url_full = "/?p=menuedit";</script>
    2. window.location.href=url_full;

    You will still get the Notice error, but that won't effect your code.
     
    Vbot, Jun 16, 2009 IP
  3. Gray Fox

    Gray Fox Well-Known Member

    Messages:
    196
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #3
    The code
    
    echo '<form action="/?'.$_SERVER['QUERY_STRING'].'" method="post">';
    
    PHP:
    is vulnerable to XSS, I'd strongly recommend switching to some alternative
     
    Gray Fox, Jun 17, 2009 IP
  4. marcnyc

    marcnyc Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for your help. That did definitely help a lot.
     
    marcnyc, Jun 17, 2009 IP