A few simple PHP questions...

Couldn't figure out where to put the header(msword) bit as doesn't seem to work without it (tried <b>test</b> with no luck) so kept going through the thread and found a link to http://phprtf.com which looks pretty good, might take me a while but may be worth it.
 
weird, I didn't set any headers, just this

Code:
<?php
$fh = fopen('something.doc','w');
fwrite($fh,'<b>some stuff!!</b>');
fclose($fh);
?>

that worked perfectly
 
I'm not sure what to say so i'll post my code and hope you point out something ridiculously easy like earlier :p

Code:
// write the file

$thecontent = "<b>Reference:</b> " . $ref . 
	"\r\n<b>Date submitted:</b> " . $date . "\r\n" . 
	"_____________________________________" .
	"\r\n\r\n<b>Submitted by:</b> " . $subby .
	"\r\n<b>Submitted to:</b> " . $subto .
	"\r\n<b>Delivery address:</b> \r\n\r\n" . $deladdress .
	"\r\n\r\n<b>Log number:</b> " . $logno . "\r\n" .
	"_____________________________________" .
	"\r\n\r\nItem 1: " . $item1 .
	"\r\nQuantity: " . $quantity1 .
	"\r\nReason: " . $reason1 . 
	"\r\nType: " . $type1 .
	"\r\nOld assets: " . $asset1 .
	"\r\nNotes: " . $notes1;

$filename = "c:\\inetpub\\wwwroot\\data\\submitted\\" . $ref . ".doc";
$somecontent = $thecontent;

$fh = fopen($filename, 'w+');

if (is_writable($filename)) {

    if (!$handle = fopen($filename, 'w+')) {
         echo "Cannot open file ($filename)";
         exit;
    }
    if (fwrite($handle, $somecontent) === FALSE) {
        echo "Cannot write to file ($filename)";
        exit;
    }
    echo "<br \><br \>Success, wrote to file ($filename)";

    fclose($handle);

} else {
    echo "The file $filename is not writable";
}
fclose($fh);

If my code is weird please tell me and i'll correct it! I notice your using ' and im using ", does that make a difference?!
 
you're doing something weird - you're running fopen and assigning it to $fh, but then you're doing it again and assigning it to $handle, but not fclose-ing $handle.

have you checked your path is right, too? for now, try writing to one in the same directory, you won't need to refer to something like c:\ - whilst you're testing to

Code:
$filename = $ref . ".doc";
 
you're doing something weird - you're running fopen and assigning it to $fh, but then you're doing it again and assigning it to $handle, but not fclose-ing $handle.

For some reason if i didn't do this it would never open the file, but as soon as i added that in it worked fine. If i didn't have it it would give the "The filename is not writable" message for some reason?

have you checked your path is right, too? for now, try writing to one in the same directory, you won't need to refer to something like c:\ - whilst you're testing to

The file is created and written alright, it writes all the data i want into the file but Word simply doesn't "process" the <b></b> tags, it displays them as text!
 
If no idea's, do you know how i can use this to save a file rather than "output" it? At the moment when you use those sample scripts they all let you save the file to your HDD but i need to save it to the server like i'm doing above?

Huge thanks for your help by the way :)
 
hey, sorry wasn't near a computer last night

in the examples, you make a call to new Rtf. There's a function in the Rtf class called save(), which allows you to pass the filename as the first argument - used in place of sendRtf (I think that's what it's called!), so this example would actually look like this

Code:
<?php

require_once("../rtf/Rtf.php");

$rtf = new Rtf();
$sect = &$rtf->addSection();
$sect->writeText('<i>Hello <b>World</b></i>.', new Font(12), new ParFormat('center'));

$rtf->save('Doc.doc');
?>
 
Ha that's strange, literally finally found that out 10 minutes ago by hurting my eyes looking through the API - it doesn't help that i don't particularly know what im looking for! Am all sorted with that bit now. :)

Next question, i think i'm going to stick with this phprtf as it looks pretty cool and should do all i need (and more). First problem i'm having is using the "setLandscape" function in the rtf class.

I've been trying variations of

Code:
$rtf->setLandscape();

But the document is always portrait :p. So question being, what is "void" (as that's what the API says it is, and how do i "set" it?!

Thanks very much for the help by the way, i missed you :D
 
void means that nothing is returned by that function, but you're likely to see stuff like boolean, string, mixed, array, int, that type of thing there. All that function seems to do is set a trigger that's picked up by the ->prepare() function when you save. Not sure what to suggest if that hasn't worked, though.
 
Turns out i had to set it using the pages height/width, apparently the landscape function sets the printing default to landscape and thats all!

Now all i have to do is try and figure out how to give people the option of ordering more than one item at one time...my only idea at the moment is to create loads of forms and PHP processing pages to co-incide with the amount of items the user wants to order...

Unless there's a better option?
 
Right then, new question!

As my form is "embedded" into the Wiki application i am using i can't do any client side validation on it so have some validation at the start of the PHP file that processes the form and creates my RTF file etc. The only problem i have is if the validation isn't passed it will send the user back to the previous page (using history.go(-1)) and the form contents has disappeared.

Obviously this could be quite annoying if you have filled out the entire form and missed one required field, and on being told you missed the filed you then have to fill out the entire form all over again!

Is there a better way of returning the user to the form without them loosing the data they entered?
 
Right then, new question!

As my form is "embedded" into the Wiki application i am using i can't do any client side validation on it so have some validation at the start of the PHP file that processes the form and creates my RTF file etc. The only problem i have is if the validation isn't passed it will send the user back to the previous page (using history.go(-1)) and the form contents has disappeared.

Obviously this could be quite annoying if you have filled out the entire form and missed one required field, and on being told you missed the filed you then have to fill out the entire form all over again!

Is there a better way of returning the user to the form without them loosing the data they entered?

instead of returning them to the previous page you could call a function that will display the form, and make it so the fields values are $_POST['email'] etc
 
Rightio, didn't realise you couldn't redirect the user back to the page and keep the POST data.

Another problem i have is that this "order form" im creating will sometimes need to order more than one item. At the moment my form and PHP processor can handle one item only, i could quite easily create 10 more forms and PHP processors that would allow up to 10 items to be ordered but surely thats a pants way of doing it?!

So next question, how can i "add" extra field to a form if a user clicks a link that says (add another item..) or something similar? And then how can i adjust my PHP script on the backend to accept any additional items and process them?
 
I'll clarify a little. When we order bit's it will usually only be one or two items, so my form currently looks like this:

Delivery Address: __________________ (select box)
Ref Number: ______________________ (text box)
Customer Email: ___________________ (text box)

Item 1
Product: _________________________ (select box, e.g. Printer, PC, TFT)
Quantity: ________________________ (select box)
Type: Replacement __ Enhancement __ (radio buttons)
Old assets: _______________________ (text box)

Other Notes: ______________________ (text box)


Obviously the current problem is, what happens if i want to order 2xPrinter's as well as 2xPC's and 2xTFT's and 2xEthernet Cables? I'd have to submit that request and then complete the form again and again for the next items! Rubbish!

So my main question is, lets say my PHP currently does this:

Code:
echo $deladdress;
echo $refnumber;
echo $custemail;

echo $item1;
echo $quantity1;
echo $type1;
echo $oldassets1;

echo $notes;

How can i change it to, for example, loop through looking for (and echo'ing)other items like $item2, $quantity2, $type2, $oldassets2, $item3, $quantity3...etc...?
 
Back
Top Bottom