Solved

Fail to get variable value after submit at php dynamic js injection form

Posted on 2010-11-23
5
305 Views
Last Modified: 2012-05-10
I create a file input area after clicked 'add button’, first element value is ‘AAA’:

<input type="text" readonly="true" name="ndiv_partd1[]" id="ndiv_partd1[]" size="30" value="AAA" maxlength="30" style="text-transform: uppercase; border: 0pt none;">

And second element with value ‘BBB’
<input type="text" readonly="true" name="ndiv_partd1[]" id="ndiv_partd1[]" size="30" value="BBB" maxlength="30" style="text-transform: uppercase; border: 0pt none;">

When I click submit button, the php can’t read and get the variable value ndiv_partd1[] at all at Firefox/Google Chrome browser.  However it work fine at Internet Explorer 8.0.

When I echo the following statement:

foreach ($ndiv_partd1 as $nndiv_lp => $ndiv_alt_val) {
echo "<BR>[".$nndiv_lp."] [".$ndiv_alt_val."]  
}

Output:
[0] [AAA] >>>>> 
[1] [BBB] >>>>>

It’s no problem for me to get the value for each variables at IE8.0, however having difficulty at those Firefox/Google Chrome browser.
0
Comment
Question by:chwong67
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 250 total points
ID: 34202856
From this page: http://www.php.net/manual/en/language.variables.external.php

"Dots and spaces in variable names are converted to underscores. For example <input name="a.b" /> becomes $_REQUEST["a_b"]. "

This means that you probably should not use '_' in names that get sent from forms to PHP.
0
 
LVL 9

Author Comment

by:chwong67
ID: 34202946
Please note that the above code work fine in Internet explorer 8 but failed in Firefox/Google Chrome browser.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 34203016
Please note that I would consider Firefox/Chrome to be correct and IE wrong.  If you remove the underscore and it still doesn't work, then I would concede that that isn't the problem.  You could try putting this code at the top of your PHP page to see what it is receiving from each browser.
print_r($_REQUEST);

Open in new window

0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 34207617
Install this and run it to see the moving parts.  You do not need to remove the underscores; but you do need to understand the risk of having two form input elements named like a.b and a_b - the mung process would destroy the value of one of these elements.

Also please read the notes on this man page.  You must address the $_POST array directly.
http://php.net/manual/en/security.globals.php

HTH, ~Ray
<?php // RAY_temp_foo.php
error_reporting(E_ALL);
echo "<pre>";

// SHOW THE SUBMITTED DATA
if (!empty($_POST))
{
    var_dump($_POST);
    foreach ($_POST["ndiv_partd1"] as $thing)
    {
        echo PHP_EOL . "HERE IS $thing";
    }
}

// DROP OUT OF PHP INTO HTML
?>

<form method="post">
<input type="text" readonly="true" name="ndiv_partd1[]" id="ndiv_partd1[]" size="30" value="AAA" maxlength="30" style="text-transform: uppercase; border: 0pt none;">
<input type="text" readonly="true" name="ndiv_partd1[]" id="ndiv_partd1[]" size="30" value="BBB" maxlength="30" style="text-transform: uppercase; border: 0pt none;">
<input type="submit">
</form>

Open in new window

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 34207628
A public version of that little script is available here:
http://www.laprbass.com/RAY_temp_foo.php
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question