RhysAndrews Posted January 31, 2009 Share Posted January 31, 2009 Hey guys. I'm attemping to setup a order form, where viewers can open a photo from a lightbox/ajax style gallery and click "Add to Order". To do this, I have hidden inputs for each photo, each with a unique name. When the "add to order" button is pressed, this javascript code is executed: var ind=0; function submitPhoto(photoNum) { photoNum = String(photoNum); getElementsByName("orderform").photoNum.name = "ph"+String(ind); ind+=1; } photoNum is the unique name of the hidden inputs. The javascript should change the name to ph0, ph1, and so on, depending on the number of photos you add to the order. The PHP script that sends the order via email then checks the values of ph0, ph1, etc. It keeps searching those variables until there's one that's empty, so it knows it's the end of the order. The PHP will then send all the values of those (which are pre-entered into the hidden inputs) via email to the order taker. Here is the section of code (its a PHP code) that displays the button and hidden input: <li><BUTTON type=\'button\' onClick=\'javascript:submitPhoto('.substr($img,0,-4).');\'>Add to Order</BUTTON><INPUT type=\'hidden\' name=\''.substr($img,0,-4).'\' value=\''.substr($img,0,-4).'\'></INPUT></li> the substr function is the 'photo code' which is actually just the photo's filename without the extension - this is what is provided to the order taker. On using this PHP code, I get nothing from $_POST["ph0"] when ordering one photo: if ($_GET["doorder"]==1) { echo $_POST["ph0"]; } I know this is complicated to understand, my apologies in advance. Thanks very much! -Rhys Andrews Link to comment https://forums.phpfreaks.com/topic/143230-changing-form-inputs-name/ Share on other sites More sharing options...
redarrow Posted January 31, 2009 Share Posted January 31, 2009 When you look at the form from the browser is the img name there. Link to comment https://forums.phpfreaks.com/topic/143230-changing-form-inputs-name/#findComment-751195 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.