Insert Html Code To A Page Via Php Script In Other Page January 31, 2023 Post a Comment i'm a little bit new for php so maybe this question is stupid. say i have a form: Solution 1: There are various ways of managing this, depending on your ultimate goal. You can just use separate files, and when user submits the form, it goes to the next page, ie. firstform.php -> SUBMIT goes to -> secondform.php, and so on. This way if you check their inputs and not what you like, you can send them back to the previous page/form with some error message to correct their choices. You can Use either GET as you are now, or POST You can use one page/file (say forms.php) and use PHP to determine what stage the user is at. Example - say you have user enter number of pictures they want, then ask for their details (may not be what you need but you get the flow idea) //FORM 1 - get number of pictures if ($_GET['whichform'] == '') { echo '<form id="createNewGallery" name="newgallery" method="GET" action="'.$_SERVER['PHP_SELF'].'"">'; echo '<input type="hidden" name="whichform" value="form1" />'; echo '<input name="submitNumOfPictures" type="submit" />'; } //FORM 2 - number of pictures submitted so ask for their details elseif ($_GET['whichform'] == 'form1') { echo '<form id="GetUserDetails" name="userdetails" method="GET" action="'.$_SERVER['PHP_SELF'].'"">'; echo '<input type="hidden" name="whichform" value="form2" />'; echo '<input name="userdetails" type="submit" />'; } Copy This will let you start with FORM1, once submitted the GET info will return true for if is FORM1, and so it will show FORM 2, and so on for FORM 3, 4, 5, etc It's a crude way in some ways, and needs tweaking (ie testing if the submitted data is as you expect etc) but it gives you the idea on how to manage multiple forms on one page. Solution 2: As Filippo Toso said, you may include the HTML file in your code.php. Perhaps, if you don't want to have two files, you may make only one file and set the form to act like that: <form id="createNewGallery" name="newgallery" method="GET" action="./"><p><strong>please choose the number of pictures you want to upload: </strong> <select name="numOfPictures" id="numOfPictures"> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> <option>9</option> <option>10</option> </select></p> <input name="submitNumOfPictures" type="submit" /> </form> <?php if (isset($_GET['numOfPictures'])){ $times = $_GET['numOfPictures']; for ($i = 1; $i <= $times; $i++){ echo '<br />select picture number '.$i.': <br />'; echo '<input name="file'.$i.'" type="file" />'; } echo '</br><input name="submitFiles" type="submit" />'; } ?> Copy (note the "action" of the form) This is, maybe, pointless, compared to the previous solution but if you don't want to have two files you may do that in once, so that once you submit you will get the results right after your form without needing any other page! edit: forgot to mention that I suppose your file is named "index.php". If not, just replace the "./" with the correct address! Solution 3: try this <form id="createNewGallery" name="newgallery" method="post" action="code.php"> <p><strong> please choose the number of pictures you want to upload: </strong> <select name="numOfPictures" id="numOfPictures"> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select></p> <input name="submitNumOfPictures" type="submit" /> </form> Copy code.php <?php $times = $_POST['numOfPictures']; echo $times; ?> Copy Share Post a Comment for "Insert Html Code To A Page Via Php Script In Other Page"
Post a Comment for "Insert Html Code To A Page Via Php Script In Other Page"