gotornot Posted October 13, 2009 Share Posted October 13, 2009 I am creating a form that generates fields dynamically on the fly as per database requirements. When i submit the form the field names are generated by the database name for the option they are. How do i collect them the other end and insert them into a db? I can add a $vale = $_REQUEST[''];for each one as there will be lots of combinations Is there any quick way of grabbing passed over data and spliting it up? Quote Link to comment Share on other sites More sharing options...
cags Posted October 13, 2009 Share Posted October 13, 2009 Depends what your dynamic fields look like.... if you did something like <input type="text" name="firstname[]" /> <input type="text" name="surname[]" /> <input type="text" name="email[]" /> <input type="text" name="firstname[]" /> <input type="text" name="surname[]" /> <input type="text" name="email[]" /> <input type="text" name="firstname[]" /> <input type="text" name="surname[]" /> <input type="text" name="email[]" /> Assuming that you validated that all fields are villed in you can then use something like... $count = count($_POST['firstname']); foreach($_POST['firstname'] as $k=>$v) { echo $v . " " . $_POST['surname'][$k] . " " . $_POST['email'][$k]; } There are other options it all depends on your preferences. Quote Link to comment Share on other sites More sharing options...
gotornot Posted October 13, 2009 Author Share Posted October 13, 2009 Hiya well its a custom shopping catr and items have different options ie clothes is size colour and finish some products dont have any they need width and depth so i worte a general script that added as many options per products as was needed. So i need a way of grabbing all passed data of these options and insertisng them into a db. Quote Link to comment Share on other sites More sharing options...
cags Posted October 13, 2009 Share Posted October 13, 2009 In that case your probably looking for something more along the lines of... <?php foreach($_POST['items'] as $k=>$v) { switch($v['type']) { case "name1": // parse information to add to db here... break; case "name2": // parse information to add to db here... break; case "name3": // parse information to add to db here... break; } } ?> <br/> <form action="" method="post"> <input type="text" name="items[0][type]" value="name1" /><input type="text" name="items[0][description]" value="Blah... blah... blah.." /><input type="text" name="items[0][quantity]" value="10" /><br /> <input type="text" name="items[1][type]" value="name2" /><input type="text" name="items[1][description]" value="Some description" /><br /> <input type="text" name="items[2][type]" value="name3" /><input type="text" name="items[2][description]" value="blah..." /><br /> <input type="submit" name="submit" /> </form> 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.