completeNewb Posted September 16, 2011 Share Posted September 16, 2011 Hi, I've got a pdf catalog which posts an order to a php form. The idea is that that the php page looks like an order form that the client can check before finally hitting 'submit' (i.e. along the lines of go to shopping cart). I'd like the php page to be editable. Meaning clients can not only look at their echoed order, but change it before committing to it. So the catalog order gets put into a php submit form with editable fields. I've read that others have accomplished this with statements like: value="<?php echo $clientName; ?>" Which should fill the client name input box on the order form with the posted variable. But it doesn't work properly for me, instead, the form field is filled with "<?xml version=" with the expected name on the line benath the input box and " /> on the line beneath that. Placing the input box declaration entirely within php tags doesn't work either (exactly the same output). <?php echo ("Name: <input class=\"inputbox\" type=\"text\" name=\"clientName\" maxlength=\"40\" value=\"$clientName\"><br>"); ?> Can anyone help? Steve Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/ Share on other sites More sharing options...
Pikachu2000 Posted September 16, 2011 Share Posted September 16, 2011 Where is the $clientName variable getting its value? That's where I'd start debugging this problem. Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1269787 Share on other sites More sharing options...
completeNewb Posted September 16, 2011 Author Share Posted September 16, 2011 Thanks for replying Pikachu2000. The var is posted from a pdf and declared with: $clientName = $_POST['clientName']; As an earlier test I simply echoed all the posted variables & they were simply that--whatever was typed in the appropriate pdf entry field. So if John Smith is the client's name then: echo $clientName is John Smith But value="<?php echo $clientName; ?>" is: <?xml version= John Smith " /> where only the first line is in the input box. Steve Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1269794 Share on other sites More sharing options...
voip03 Posted September 16, 2011 Share Posted September 16, 2011 <?xml version= John Smith " /> Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1269797 Share on other sites More sharing options...
completeNewb Posted September 16, 2011 Author Share Posted September 16, 2011 Hi, assuming that it is the pdf adding the extra characters (lines): <?xml version= John Smith " /> (Which echo on its own doesn't display, but value="<?php echo $clientName; ?>" does): How might I remove them? Steve Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270082 Share on other sites More sharing options...
xyph Posted September 16, 2011 Share Posted September 16, 2011 That is echo on it's own. That's the odd part. Post your entire code, it's obvious that SOMETHING is changing your variables. There's no way an echo in one place should be different than an echo in another place unless that variable was change. Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270088 Share on other sites More sharing options...
Pikachu2000 Posted September 16, 2011 Share Posted September 16, 2011 One idea: look at the source of the page when you echo the variable on its own. I'll bet the xml is there in the source, but not being rendered by the browser. Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270091 Share on other sites More sharing options...
xyph Posted September 16, 2011 Share Posted September 16, 2011 One idea: look at the source of the page when you echo the variable on its own. I'll bet the xml is there in the source, but not being rendered by the browser. That shouldn't render considering the value is in the tag. <?xml version= John Smith " /> Should not be displayed at all. Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270094 Share on other sites More sharing options...
Pikachu2000 Posted September 16, 2011 Share Posted September 16, 2011 True (duh). Back to square one I guess; can't tell much more without the code. Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270095 Share on other sites More sharing options...
xyph Posted September 16, 2011 Share Posted September 16, 2011 Better to suggest something than stay silent I think your best bet is to print_r( $_POST ); at the start of the script, then do it again right before you echo the values in the form. To anyone reading - this is why developers avoid global variables, and prefer to do most of the dirty work in a local/function/class scope. It can become VERY hard to tell where these variables are changed if every included file/function/class is able to modify them. Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270096 Share on other sites More sharing options...
completeNewb Posted September 16, 2011 Author Share Posted September 16, 2011 Thanks for trying to help me here. I'm beginning to suspect it's something to do with the fact the post come from a pdf, since no one's saying "You can't use value=\"$clientName\" I'll try making a test submit html page and see if I can insert values that way (won't help with the problem though, the catalog is a pdf). Here's the offending code: I'll see if I can attach a pic of the output. (The clientName is 'too' sorry, was in a hurry & not thinking.) <body> <?php print_r( $_POST ); $clientName= $_POST['clientName']; echo $clientName; echo ("client Name: <input class=\"inputbox\" type=\"text\" name=\"clientName\" maxlength=\"40\" value=\"$clientName\"><br>"); ?> <form name="form1" method="post" action=""> <input name="name" type="text" id="name" value="<?php echo $clientName; ?>"> <form action="orderSent.php" method="post"> <input type="submit" /> </p> </form> </body> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270099 Share on other sites More sharing options...
Pikachu2000 Posted September 16, 2011 Share Posted September 16, 2011 Where are all the "too"s coming from? Copy and paste the page source here also. That may shed some light on this. Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270104 Share on other sites More sharing options...
completeNewb Posted September 16, 2011 Author Share Posted September 16, 2011 Sorry Pikachu2000, the 'too' is the name (!) i.e. not John but too. (I was in a hurry). And that (above) is all the code in the current submit.php which receives the post--the actual source (of the post vars) is a pdf button (in a pdf catalog) set to 'submit a form to html' this sends the post to submit.php. But I've just discovered the script above works fine by declaring: $clientName = 'John'; i.e. hard code the var instead of getting it from $_POST. So there're 'invisible' lines in the post received from the pdf, only revealed by a "value=" statement. Any ideas how to strip them from the $_POST? Steve Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270106 Share on other sites More sharing options...
PFMaBiSmAd Posted September 16, 2011 Share Posted September 16, 2011 I have no way of testing this, but in Acrobat, where you created the PDF form - Highlight the submit button and click the XML Source tab. Below the tag, near the tag for the button, find and change format="formdata" to format="urlencoded" Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270109 Share on other sites More sharing options...
completeNewb Posted September 16, 2011 Author Share Posted September 16, 2011 Thanks PFMaBiSmAd, Well, your suggestion sure lifted my mood for a while, and in fact it might lead to a workaround, but it didn't quite work. I've been using acrobat to edit the pdf. It seems acrobat's HTML submit feature comes with weird formatting (as described above) and there's no way to remove it with acrobat (or Foxit). If anyone knows how i can remove this extra formatting with php after the POST then please let me know (all suggestions appreciated). Acrobat won't let me change this formatting, however Adobe's life cycle designer does. Designer has format="urlencoded" as the default setting. The bummer is that designer won't pass my product code as quantity array. Rather it simply posts every field in the pdf (all mashed together, [prodCode_6747_] rather than prodCode[6747]). So at the moment it seems I can post values but lose the product array or visa versa (am still playing with this). Once again If anyone knows how i can remove the extra formatting with php after the POST then please let me know (all suggestions appreciated). Steve Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270148 Share on other sites More sharing options...
xyph Posted September 17, 2011 Share Posted September 17, 2011 Why don't you print_r( $_POST ); at the start of the script, view the source of the page and post it here. You can use PHP to modify the strings easily Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270150 Share on other sites More sharing options...
completeNewb Posted September 17, 2011 Author Share Posted September 17, 2011 Hi, here's the whole submit page. Currently all this page does is: print_r($_Post) echo a single posted var ($pharmName) (changed from clientName) And try to fill two html fields (each time in a slightly different fashion) with the variable $pharmName. If I can get the formatting issues to work I'll be adding your code (xyph ) from the earlier question you helped me with (i.e. where prodCode => qty was matched to product descriptions). This current page is a test to see if I can fill an HTML form with all the values from a pdf catalog. There will (if this works) be several catalogs. Each will have the same address fields but different brands. Then will follow a list of ordered products and quantities. The client will be able see their pdf order as a single web page before finally submitting it. As it's a form they'll also be able to make last minute changes. [code] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php print_r( $_POST ); $pharmName= $_POST['pharmName']; echo $pharmName; echo ("Pharmacy: <input class=\"inputbox\" type=\"text\" name=\"pharmName\" maxlength=\"40\" value=\"$pharmName\"><br>"); ?> <form name="form1" method="post" action=""> <input name="name" type="text" id="name" value="<?php echo $pharmName; ?>"> <form action="orderSent.php" method="post"> <input type="submit" /> </p> </form> </body> </html> The attached pic shows the output when sent from an acrobat saved pdf. Only two products were ordered [6722] and [6724]. The problem is "<?xml version=" appears in the input box with the actual input below the box followed by these chars " /> Sending from a Adobe designer saved pdf correctly fills in the form (no extraneous chars) but the print_r($_Post) displays every field and button in the pdf and the products are in the form: [prodCode_6723_] => 7 [prodCode_6730_] => [prodCode_6731_] => Meaning the products are not in an array and all products are present whether ordered or not. So I won't be able to loop through the prodCode array and display ordered products alongside their product descriptions. (Although possibly I could find a way to do this). Steve [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270157 Share on other sites More sharing options...
PFMaBiSmAd Posted September 17, 2011 Share Posted September 17, 2011 ^^^ That's not the 'view source' of the page in your browser. The reason for asking for that is so that all the characters and tags present will be displayed. Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270159 Share on other sites More sharing options...
completeNewb Posted September 17, 2011 Author Share Posted September 17, 2011 Sorry, I don't get it. I did look at the source but it doesn't seem to have much info (all the php is server side). Here it is though. Is this what you're after? If not, please advise. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> Array ( ) <br /><br> </body> </html> The above is from the pdf with the prod array working but the bung value = fields (i.e. pdf saved with acrobat) But view source is the same for bung product array with working value= fields (i.e. pdf saved with designer) Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270160 Share on other sites More sharing options...
completeNewb Posted September 17, 2011 Author Share Posted September 17, 2011 Oops, I just looked with IE (was using firefox) seems there's a lot more on offer. Sorry, Steve <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> Array ( [Acc] => <?xml version="1.0"?><body xfa:APIVersion="Acroform:2.6.7116.0" xfa:spec="2.1" xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"><p dir="ltr" style="margin-top:0pt;margin-bottom:0pt;font-family:Arial;font-size:12pt">1234</p></body> [contactName] => <?xml version="1.0"?><body xfa:APIVersion="Acroform:2.6.7116.0" xfa:spec="2.1" xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"><p dir="ltr" style="margin-top:0pt;margin-bottom:0pt;font-family:Arial;font-size:12pt">me</p></body> [pharmName] => <?xml version="1.0"?><body xfa:APIVersion="Acroform:2.6.7116.0" xfa:spec="2.1" xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"><p dir="ltr" style="margin-top:0pt;margin-bottom:0pt;font-family:Arial;font-size:12pt">Some pharm</p></body> [prodCode] => Array ( [6722] => 2 [6724] => 2 ) [suburbName] => <?xml version="1.0"?><body xfa:APIVersion="Acroform:2.6.7116.0" xfa:spec="2.1" xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"><p dir="ltr" style="margin-top:0pt;margin-bottom:0pt;font-family:Arial;font-size:12pt">Somewhere</p></body> [wSalerName] => wholesaler [button6] => ) <?xml version="1.0"?><body xfa:APIVersion="Acroform:2.6.7116.0" xfa:spec="2.1" xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"><p dir="ltr" style="margin-top:0pt;margin-bottom:0pt;font-family:Arial;font-size:12pt">Some pharm</p></body>Pharmacy: <input class="inputbox" type="text" name="pharmName" maxlength="40" value="<?xml version="1.0"?><body xfa:APIVersion="Acroform:2.6.7116.0" xfa:spec="2.1" xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"><p dir="ltr" style="margin-top:0pt;margin-bottom:0pt;font-family:Arial;font-size:12pt">Some pharm</p></body>"><br> <form name="form1" method="post" action=""> <input name="name" type="text" id="name" value="<?xml version="1.0"?><body xfa:APIVersion="Acroform:2.6.7116.0" xfa:spec="2.1" xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"><p dir="ltr" style="margin-top:0pt;margin-bottom:0pt;font-family:Arial;font-size:12pt">Some pharm</p></body>"> <form action="orderSent.php" method="post"> <input type="submit" /> </p> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270161 Share on other sites More sharing options...
completeNewb Posted September 17, 2011 Author Share Posted September 17, 2011 Hi, looking at the above (the IE source) I'm thinking that if I turn the address fields into an array like the prodCode array I might get clean variables. Will try that after lunch. Thanks all. Steve Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270164 Share on other sites More sharing options...
completeNewb Posted September 17, 2011 Author Share Posted September 17, 2011 If anyone else ever experiences this particular horror, the answer is to uncheck rich text formatting on the posted pdf fields. Thanks to everyone who helped me. I'm immensely grateful for your efforts. I know how to make this work now--I can dump the address array--but I'd rather not. So I do have one last question. Why isn't my if ( $addrItem = 'pharmName' ) statement working? Somehow it appears to put the wrong value (the account number) into $pharmName when, of course, I'm tryying for the input pharmacy name. Here's my page code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php echo 'This is post: <br>'; print_r( $_POST ); echo '<br>'; echo '<br>'; echo '<br>'; $address = $_POST['addr']; $orders = $_POST['prodCode']; foreach( $address as $addrItem => $addrLine ) { if ( $addrItem = 'pharmName' ) { echo 'fld name: '.$addrItem.' user typed: '.$addrLine; $pharmName = $addrLine; break; } echo '<br>'; } echo '<br>'; echo ("Pharmacy: <input class=\"inputbox\" type=\"text\" name=\"pharmName\" maxlength=\"40\" value=\"$pharmName\"><br>"); ?> <form name="form1" method="post" action=""> <input name="name" type="text" id="name" value="<?php echo $pharmName; ?>"> <form action="orderSent.php" method="post"> <input type="submit" /> </p> </form> </body> </html> And here's the source (if that helps) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> This is post: <br>Array ( [addr] => Array ( [Acc] => Acc num [contactName] => contact name [pharmName] => Pharm name [suburbName] => A suburb [wSalerName] => wsaler ) [prodCode] => Array ( [6722] => 2 [6724] => 2 ) [button6] => ) <br><br><br>fld name: pharmName user typed: Acc num<br>Pharmacy: <input class="inputbox" type="text" name="pharmName" maxlength="40" value="Acc num"><br> <form name="form1" method="post" action=""> <input name="name" type="text" id="name" value="Acc num"> <form action="orderSent.php" method="post"> <input type="submit" /> </p> </form> </body> </html> Steve Quote Link to comment https://forums.phpfreaks.com/topic/247246-form-fill-problem/#findComment-1270179 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.