Jump to content

Possible?


play_

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/64596-possible/
Share on other sites

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
}

Link to comment
https://forums.phpfreaks.com/topic/64596-possible/#findComment-322071
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/64596-possible/#findComment-322072
Share on other sites

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

 

Link to comment
https://forums.phpfreaks.com/topic/64596-possible/#findComment-322074
Share on other sites

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
}

Link to comment
https://forums.phpfreaks.com/topic/64596-possible/#findComment-322097
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.