1

I'm creating a small form to generate css files for a project, just swapping out a few colours. You can find a working example here:

http://breadadams.com/cssgen

I've got it working to force save a php file (that is linked via action="" in form) as css file on load, replacing some values with values taken from the form fields.

I need to generate a few more css files, and one xml file. All the same style, taking color values and replacing.

I was thinking of creating multiple .php files that force download in specific format with

header("Content-Disposition: attachment; filename=\"name.type\"");

However multiple files can't be inserted in the action="" field. Is there any other way?

Or maybe generating all these files from in one .php file (though I think header() functions affect the entire file?)?

I'd then be compiling all these files into zip, using ZipArchive, that would be downloaded via the Download .css button.

Any help would be great.

Brad Adams
  • 2,066
  • 4
  • 29
  • 38
  • 1
    *"I just can't think of how I send form data to all the php files."* - You're going to have to elaborate on that. – Funk Forty Niner Oct 01 '14 at 18:31
  • I was thinking the same, have cleaned up my question. – Brad Adams Oct 01 '14 at 18:39
  • 1
    See these Q&A's on Stack http://stackoverflow.com/q/16390601/ http://stackoverflow.com/q/5690794/ along with some of the links in the answers. I hope this will be of some help. I had a piece of code somewhere in my libraries, but for the life of me, I can't find it right now. I'll let you know if I do. – Funk Forty Niner Oct 01 '14 at 18:50

1 Answers1

0

Try this:

<form name="form1" action="File1.php" onsubmit="return onSubmit ()"...>
    <input type='xxx' name="field1"...>
    ...
</form>

<form name="form2" target="name_for_form2_results" action="File2.php"...>
    <input type="hidden" name="field1">
    ...
</form>

<script language="javascript">
function onSubmit ()
{
    document.form2.field1.value = document.form1.field1.value;
    ...
    document.form2.submit ();
    ...
    return true;     //  Submits Form1
}
</script>

Specifying a target on the form should open up a new window with that name. The first form has the input fields, the second has the same name but are hidden fields and don't appear on the screen. onSubmit copies the values from the first to all the others before submitting each of them.

The implementation could be improved but I kept it simple for clarity.

Mike
  • 2,721
  • 1
  • 15
  • 20
  • Thanks @Mike, I see where you're going with this. Although I don't quite understand `target="name_for_form2_results"` is this just to force a new window that would load the results (the file download) of `File2.php`? Or do I replace this with something? Also, I'd need the same amount of fields in each form right? Same name, class, etc. just using `type="hidden"`? – Brad Adams Oct 02 '14 at 19:02
  • The target='x' is to open the results in a new window. You could use "target='blank'" but I figure things could get a bit hectic if you hit refresh having missed a few windows. By giving them the same name, the new results would overwrite the existing window or create a new one if it doesn't exist. You don't need the same number of fields or even the same name so long as a. they are what the server is expecting and b. you know how to copy the values across. What you have is one form for entering data, several for submitting it and a method of copying from one to the other when needed. – Mike Oct 02 '14 at 19:53