thenorman138 Posted July 20, 2018 Share Posted July 20, 2018 Overview: I've made a CMS that has the intent of the user creating one page, which is comprised of multiple assigned panels, each of which has it's own assinged content. I have a simple full width page template that has two divs corresponding to panels, with the respective IDs 'background' and 'full' fullWidth.php <div class="row middle" id="background"> <div class="col-lg-12 fullWidth" id="full"> <div class="fullContent" style="background-color: white; height: 100%;"> </div> </div> </div> My templates.php file gets the URL value from the link that called it and loads the template based on the value. In this case the value is 1 so it loads fullwidth.php. What I'm trying to do though is take the div IDs from fullwidth.php and assign them to PHP variables based on the ID. So in the below example, div ID full would have $panelType of 1 and div ID background would have $panelType of 8. Without my below pseudo code block, if I just set $panelType = 1 and submit the form calling addPage.php, everything works fine but it only works for the one panel type. However, with this example below I want to set multiple panel types which would correspond with multiple instances of the hidden inputs. I'm trying to solve two issues: 1.) Assiging multiple panelType instances according to DIV ID, which includes looping multiple hidden inputs, and 2.) making sure that addPage.php inserts correctly meaning inserting one page record, getting that page ID, then inserting multiple content records (getting each ID) and inserting multiple panel records (using the one page ID and the multiple corresponding content IDs) Again, If I just assign $panelType = 1 and do this whole process, it succesfully creates the page record, content record and panel record. But I need to alter this for multiple $panelType variables as well as set those $panelType variables accordingly Templates.php <?php $value = isset($_GET['value']) ? $_GET['value'] : 1;?> <?php if($value == 1){ include 'class/fullWidth.php' /*$panelType = 1*///I've been using this to test and it successfully inserts one page record, one content record, and one panel record /*pseudo code for what I'm trying to attempt, not currently using this*/ $panel = $html->find('div[id]'); if ($panel == 'full') { $panelType = 1; }elseif ($panel == 'background') { $panelType = 8; } } ?> <form action="addPage.php" method="post"> <input type="hidden" name="pageType" value="<?php echo $value;?>"> <!--This will always be one value, the URL value that I GET up top--> <input type="hidden" name="panelType" value="<?php echo $panelType;?>"> <!--This, I've been testing with one $panelType but now it needs to be multiple. In this example, I would be expecting $panelType of 1 and 8--> <input type="hidden" id="new" name="page_content" value=""><!--I'm using javascript to set this to page content from TInyMCE, there will be multiple of these--> <input class="form-control" id="addTitle" name="addTitle"> <input class="form-control" id="durationSet" name="durationSet"> <input type="submit" name="Save Page"> </form> addPage.php /***CREATING ONE PAGE INSERT***/ $page_type = $_POST['pageType']; $title = $_POST['addTitle']; $duration = $_POST['durationSet']; $addpage = " INSERT INTO pages (title, page_type_id, display_id, duration) VALUES ('$title','$page_type','$display_id','$duration'); "; if ($mysqlConn->query($addpage) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $addpage . "<br>" . $mysqlConn->error; } $page_id = $mysqlConn->insert_id; //Get this page ID for panel inserts /***CREATING MULTIPLE CONTENT INSERTS***/ $content = $_POST['page_content']; //Should have multiple of these $addContent = " INSERT INTO content(content) VALUES('$content'); "; if ($mysqlConn->query($addContent) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $addContent . "<br>" . $mysqlConn->error; } $cont_id = $mysqlConn->insert_id; //Get these content IDs for panel inserts /***CREATING MULTIPLE PANEL INSERTS***/ $panelID = $_POST['panelType']; $addPanel = " INSERT INTO panels(panel_type_id, page_id, cont_id) VALUES ('$panelID', '$page_id', '$cont_id'); "; if ($mysqlConn->query($addPanel) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $addPanel . "<br>" . $mysqlConn->error; } Quote Link to comment Share on other sites More sharing options...
thenorman138 Posted July 20, 2018 Author Share Posted July 20, 2018 @dalecosp this is the question I was referencing, it uses a lot of the principals from the last question but I'm trying to set input types for the different divs and then loop if possible Quote Link to comment Share on other sites More sharing options...
thenorman138 Posted July 23, 2018 Author Share Posted July 23, 2018 @requinix this is a further developed example of a question you helped me with the other day. Could you help me understand how I would serialize here? Basically submitting multiple records for each panel type but only one record for page type 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.