play_ Posted August 13, 2007 Share Posted August 13, 2007 I thought of ways of doing this but don't think it's possible. So i have a form: <form action="form.php" method="post" /> <input type="text" name="form_name" /> <input type="submit" name="submit" /> The form action is form.php. However, inside the form, i have an input called "form_name", and what i want to do is, when the form is submitted, php creates a file with whatever value for "form_name". So, say in the form_name field, someone writes "jan reports". When the form is submitted, the form action becomes 'jan reports.php'. sounds absurd but just throwing it out there Quote Link to comment https://forums.phpfreaks.com/topic/64596-possible/ Share on other sites More sharing options...
cooldude832 Posted August 13, 2007 Share Posted August 13, 2007 very easily look into file handlers, but be careful that you don't do it so basicaly because you will generate duplicate fill errors or a spam attack Quote Link to comment https://forums.phpfreaks.com/topic/64596-possible/#findComment-322068 Share on other sites More sharing options...
play_ Posted August 13, 2007 Author Share Posted August 13, 2007 More details please. Quote Link to comment https://forums.phpfreaks.com/topic/64596-possible/#findComment-322069 Share on other sites More sharing options...
cooldude832 Posted August 13, 2007 Share Posted August 13, 2007 read http://www.w3schools.com/php/php_ref_filesystem.asp then ask questions Quote Link to comment https://forums.phpfreaks.com/topic/64596-possible/#findComment-322070 Share on other sites More sharing options...
btherl Posted August 13, 2007 Share Posted August 13, 2007 You want to generate new scripts based on form input? It's certainly possible, but I can't imagine any situation in which that would be the best option. Is there any problem with deciding which code to run based on a form variables, like so: if ($_REQUEST['form_name'] === 'jan report') { # Do jan reports stuff } elseif ($_REQUESt['form_name'] === 'yearly report') { # Do yearly report stuff } Quote Link to comment https://forums.phpfreaks.com/topic/64596-possible/#findComment-322071 Share on other sites More sharing options...
cooldude832 Posted August 13, 2007 Share Posted August 13, 2007 oh wait i read your request wrong. I think yes something along that lines is more along the lines, but first off it shouldn't be a text input but a drop down menu (select) and secondly make the action be the same, but have the action in the action.php page be a switch base don include as suggested Quote Link to comment https://forums.phpfreaks.com/topic/64596-possible/#findComment-322072 Share on other sites More sharing options...
play_ Posted August 13, 2007 Author Share Posted August 13, 2007 btherl, that's not it. I probably didn't explain very well, sorry. I'll try again. What i have a is a form generator. So when the user clicks "generate", an html form gets generated. here's where it works: [link]http://noobcircle.com/alex/[/link] If you look at the source, you'll see "<form action="form.php" method="post">". But, i want the form action to be, whatever the user types in the form_name. So if the user types "hello" in form_name, php would generate a file called hello.php, and the html would be outputted there Quote Link to comment https://forums.phpfreaks.com/topic/64596-possible/#findComment-322074 Share on other sites More sharing options...
play_ Posted August 13, 2007 Author Share Posted August 13, 2007 cooldude, the form action page needs to be created on the fly. Quote Link to comment https://forums.phpfreaks.com/topic/64596-possible/#findComment-322076 Share on other sites More sharing options...
cooldude832 Posted August 13, 2007 Share Posted August 13, 2007 why? that makes no sense at all on the needs of this idea? Quote Link to comment https://forums.phpfreaks.com/topic/64596-possible/#findComment-322081 Share on other sites More sharing options...
btherl Posted August 13, 2007 Share Posted August 13, 2007 Hmm.. Do you want all these form submissions to go back to your script, even though it's using a different name? I still don't get what you are trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/64596-possible/#findComment-322091 Share on other sites More sharing options...
Fadion Posted August 13, 2007 Share Posted August 13, 2007 U can generate a file when the user clicks submit using fopen(), but still remains the problem of sending the form to that page. Normaly that new file will be generated after the form has been submited and the only way is to save all the post variables to sessions and redirect the user to the newly generated page. if(array_key_exists('form_name', $_POST){ $filename = $_POST['form_name'] . ".php"; $hande = fopen($filename, 'w'); fwrite($handle, 'lots of data here'); $fclose($handle); $_SESSION['someData'] = $_POST['someData']; //do this for all your post variables //redirect to $filename } Quote Link to comment https://forums.phpfreaks.com/topic/64596-possible/#findComment-322097 Share on other sites More sharing options...
cooldude832 Posted August 13, 2007 Share Posted August 13, 2007 actually if you make the submit page be the form its self then pre loading any data say if($_POST['submit']){header("location: $_POST['action']")} Quote Link to comment https://forums.phpfreaks.com/topic/64596-possible/#findComment-322106 Share on other sites More sharing options...
play_ Posted August 13, 2007 Author Share Posted August 13, 2007 Is there a way to take part of a page, and write it to a file? that way when the form gets outputted to form.php, i can take the html in it, write that html to form_name.php Quote Link to comment https://forums.phpfreaks.com/topic/64596-possible/#findComment-322199 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.