dadamssg87 Posted May 24, 2011 Share Posted May 24, 2011 I'm have a form with at least 3 fields(name, price, and date). I have some jquery that produces another date form input every time a certain link is clicked so there can be several date inputs. The first one(not dynamically created) has the form name "date_1". All the jquery produced inputs have the name "in_123435443453". The number after "in_" is the current timestamp. I'm trying to cycle through only the POSTs that start with "in_" and take their value to insert into database. I can't figure out how to grab the date("in_25346435253") POST in the foreach loop though because they're all unique. I'm using the codeigniter framework. That's why the code to insert into the db make look weird. <?php foreach($this->input->post() as $key => $value) { $start = substr($key, 0, 3); if($start == "in_") { $cal_id = $this->input->post('cal_id'); $exc_name = $this->input->post('exc_name'); $date = $this->input->post('???'); // <-- part i need help with $price = $this->input->post('price'); $date = date("Y-m-d 00:00:00",strtotime($date)); $data = array( 'cal_id' =>$cal_id, 'name' => $exc_name, 'date' => $date, 'price' => $price ); $this->db->insert('Exceptions', $data); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/237363-foreach-_post-help/ Share on other sites More sharing options...
Psycho Posted May 24, 2011 Share Posted May 24, 2011 Change the JavaScript code to create the date input names so they will be interpreted as a sub-array in the POST data. Create ALL the date input fields with the same name followed by brackets. Example <input type="text" name="dates[]" /> Then in your PHP code you can loop through all of the date inputs as follows: foreach($_POST['dates'] as $dateValue) { //Do something with $dateValue } Quote Link to comment https://forums.phpfreaks.com/topic/237363-foreach-_post-help/#findComment-1219722 Share on other sites More sharing options...
dadamssg87 Posted May 24, 2011 Author Share Posted May 24, 2011 genious..thanks Quote Link to comment https://forums.phpfreaks.com/topic/237363-foreach-_post-help/#findComment-1219732 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.