jamina1 Posted May 25, 2007 Share Posted May 25, 2007 Hey guys. I have a form that I am altering after page load with javascript. Basically I have a button that inserts another text field into the form which the user can fill out. Its for a calendar, and I'm allowing them to optionally add multiple days for an event. Each box that is created has the same name with [] on the end to make it an array. When I view the post array with print_r($_POST), only the first textbox's value shows up. This is the only textbox in the form when the page loads. Simplified example: <form name="calform" action="process.php" method="post"> <input name="startday[]" type="text" class="bordered" size="25" /> <input type="button" onclick="add_one_more()" value="Add another date" /> // if the user hits the add button it adds this input field after pageload <input name="startday[]" type="text" class="bordered" size="25" /> </form> And here's what I'd get from that form Array ( [startday] => Array ( [0] => test1 ) ) A button inside the form basically adds another <input> tag between the <form> tags. Why isn't PHP seeing the data? Quote Link to comment Share on other sites More sharing options...
Caesar Posted May 25, 2007 Share Posted May 25, 2007 Where are you printing out the array? Before or AFTER the form is submitted? Quote Link to comment Share on other sites More sharing options...
Wildbug Posted May 25, 2007 Share Posted May 25, 2007 Can you post the JavaScript? Quote Link to comment Share on other sites More sharing options...
jamina1 Posted May 25, 2007 Author Share Posted May 25, 2007 Where are you printing out the array? Before or AFTER the form is submitted? I'm printing the array directly from the process.php page the form points to. Right now as debugging, I'm forgoing everything besides the print_r command so I can see what's passing to PHP. Quote Link to comment Share on other sites More sharing options...
jamina1 Posted May 25, 2007 Author Share Posted May 25, 2007 The javascript has to insert data into a table structure so its complicated. The command that actually prints out the <input> field is element.innerHTML like so: k.innerHTML = "<input name=\"starttime[]\" type=\"text\" class=\"bordered\" size=\"25\" />" The javascript works perfectly, its the PHP I'm having issues with. Even if I assign the javascript inserted text boxes a predetermined value with value="something" that doesn't show up in the $_POST array. Quote Link to comment Share on other sites More sharing options...
Wildbug Posted May 25, 2007 Share Posted May 25, 2007 Well, if it's not showing up in the $_POST data, then it's a pre-PHP problem. The web browser is not recognizing the new element as part of the form and is not sending the data. Quote Link to comment Share on other sites More sharing options...
jamina1 Posted May 25, 2007 Author Share Posted May 25, 2007 How do I fix that? I'm using firebug to make sure the format and scripting is right. It inserts the <input> field perfectly. Why isn't the form seeing it? Quote Link to comment Share on other sites More sharing options...
phpsocko Posted April 28, 2008 Share Posted April 28, 2008 Perhaps you're using two forms on your form page. I was having a similar problem and just solved it. The problem I was having: my dynamic dropdown, drawn from an external PHP page using AJAX, was populating fine, but my $_POST array on the resulting page was not listing the chosen value in my dynamic list. Here's what I did to solve the problem. In my PHP page called by my AJAX routing, I modified my <select> statement as follows: <select name="veModel" id="veModel" onchange="partSearch.veModel.value=veModel.value; alert(partSearch.veModel.value)"> ... where partSearch is the name of the veModel field's parent form on the search page. The alert() is in there for debugging. You will, of course, want to remove this after you verify the fix works for you. Hope this helps! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.