jad3z Posted March 2, 2014 Share Posted March 2, 2014 Hello guys! Thanks for reading my topic! I am kinda new to PHP and i try to get all these forms in 1 page Can you guys help me with that? start.php <?php $file = 'user01.ini'; if($_SERVER['REQUEST_METHOD'] == 'POST') { $data = ''; foreach($_POST AS $name=>$value) { $data .= $name . '=' . $value .PHP_EOL; } file_put_contents($file, $data, LOCK_EX); if(file_exists($file)) { echo 'Saved in <a href="' . $file . '">' . $file . '</a>'; } else { echo 'Failed'; } } if(file_exists($file)) { $ini = parse_ini_file($file); } ?> <form method="POST"> <label>IP</label> <input type="numbers" name="ip" value="<?php echo (isset($ini['ip']) ? $ini['ip'] : '127.0.0.1'); ?>" /><br /> <label>Users</label> <input type="number" name="users" value="<?php echo (isset($ini['users']) ? $ini['users'] : '10'); ?>" /><br /> <label>Website</label> <input type="text" name="website" value="<?php echo (isset($ini['website']) ? $ini['website'] : 'http://'); ?>" /><br /> <button>Start</button> </form> add.php <?php $file = fopen("user01.ini","r"); if(!file) { echo("ERROR:cant open file"); } else { $buff = fread ($file,filesize("user01.ini")); print $buff; } $file = 'user01.ini'; if($_SERVER['REQUEST_METHOD'] == 'POST') { $data = ''; foreach($_POST AS $name=>$value) { $data .= $name . '=' . $value .PHP_EOL; } file_put_contents($file, $data, LOCK_EX); if(file_exists($file)) { echo 'Saved in <a href="' . $file . '">' . $file . '</a>'; } else { echo 'Failed'; } } if(file_exists($file)) { $ini = parse_ini_file($file); } ?> <form method="POST"> <label>Add Users</label> <input type="number" name="addusers" value="<?php echo (isset($ini['addusers']) ? $ini['addusers'] : '10'); ?>" /><br /> <button>Add</button> <button>Stop</button> </form> stop.php <?php $file = 'user01.ini'; if($_SERVER['REQUEST_METHOD'] == 'POST') { $data = ''; foreach($_POST AS $name=>$value) { $data .= $name . '=' . $value .PHP_EOL; } file_put_contents($file, $data, LOCK_EX); if(file_exists($file)) { echo 'Saved in <a href="' . $file . '">' . $file . '</a>'; } else { echo 'Failed'; } } if(file_exists($file)) { $ini = parse_ini_file($file); } ?> <form method="POST"> <label>Server has stopped</label><br> <label>IP</label> <input type="numbers" name="ip" value="<?php echo (isset($ini['ip']) ? $ini['ip'] : '127.0.0.1'); ?>" /><br /> <label>Users/label> <input type="number" name="users" value="<?php echo (isset($ini['users']) ? $ini['users'] : '10'); ?>" /><br /> <label>Website</label> <input type="text" name="website" value="<?php echo (isset($ini['website']) ? $ini['website'] : 'http://'); ?>" /><br /> <button>Start</button> </form> Is it possible to code this on one page? Maby with echo function ? start.php start > add.php (index.php?p=add) add.php add > add.php (index.php?p=add)stop > stop.php (index.php?p=stop) stop.phpstart > start.php (index.php?p=start) Thanks in advanced guys! Im new to php and i think this forum is the place to be! Link to comment https://forums.phpfreaks.com/topic/286658-multiple-formsinfo-in-1-page-echo/ Share on other sites More sharing options...
ginerjm Posted March 2, 2014 Share Posted March 2, 2014 Read thru your code but don't know what you are trying to do. Can you at least describe your goal. And - please define what you mean by page and form, just to be sure we agree. Link to comment https://forums.phpfreaks.com/topic/286658-multiple-formsinfo-in-1-page-echo/#findComment-1471264 Share on other sites More sharing options...
jad3z Posted March 2, 2014 Author Share Posted March 2, 2014 Link to comment https://forums.phpfreaks.com/topic/286658-multiple-formsinfo-in-1-page-echo/#findComment-1471272 Share on other sites More sharing options...
mac_gyver Posted March 2, 2014 Share Posted March 2, 2014 you need a simple 'page controller' that will determine what action the code on the page takes and what content is displayed on the page when it receives a request. you can use a switch/case statement with an include statement in the different case conditions to include the appropriate code you need for each case. Link to comment https://forums.phpfreaks.com/topic/286658-multiple-formsinfo-in-1-page-echo/#findComment-1471275 Share on other sites More sharing options...
jad3z Posted March 2, 2014 Author Share Posted March 2, 2014 you need a simple 'page controller' that will determine what action the code on the page takes and what content is displayed on the page when it receives a request. you can use a switch/case statement with an include statement in the different case conditions to include the appropriate code you need for each case. Thanks for the response Gyer! Do you got any examples? Or tutorial/links ? THanks in advanced Link to comment https://forums.phpfreaks.com/topic/286658-multiple-formsinfo-in-1-page-echo/#findComment-1471276 Share on other sites More sharing options...
mogosselin Posted March 3, 2014 Share Posted March 3, 2014 So, you could use a central php script that plays the role of a controller. Then, based on the action, this central PHP script will choose which PHP (that you already have) to include. <?php switch ($action) { case "add": include 'add.php'; break; case "start": include 'start.php'; break; case "stop": include 'stop.php'; break; } ?> So you need your form to always call this script and pass a parameter called "action" depending on the button clicked. Does it make sense? Link to comment https://forums.phpfreaks.com/topic/286658-multiple-formsinfo-in-1-page-echo/#findComment-1471294 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.