PDF Submit and $_POST

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
littlemetz85
Forum Newbie
Posts: 10
Joined: Mon Jul 23, 2007 5:23 pm

PDF Submit and $_POST

Post by littlemetz85 »

I've been working on this project for awhile now but still can't get it to work so I'm turning to all of you for some help. I have made a PDF application with a HTTP submit button at the bottom. This submits to a php script that I have on my server. What I want to do is to take the submitted data and save it as an XML file on my server. I have been using the $_POST method to get the data sent to the script but it puts it in an array. I can't figure out from here how to make it into an XML file. Any suggestions?

Thanks, Paul
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

littlemetz85
Forum Newbie
Posts: 10
Joined: Mon Jul 23, 2007 5:23 pm

Post by littlemetz85 »

I tried that but it seems but $_POST seems to be putting all the text in a single part of the array so there is no way to separate it. Is there a different method that I should use instead of $_POST? Or a different way to format my PDF submit button?

Thanks, Paul
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It would probably help to show us what is being seen by PHP.
littlemetz85
Forum Newbie
Posts: 10
Joined: Mon Jul 23, 2007 5:23 pm

Post by littlemetz85 »

when I do a print_r($_POST) this is what shows:

PaulAddress=123 Fake LaneCity=MyCityCellPhoneNumber=1234567891Email=MyMail@Gmail.com

I also get the same output using:

foreach ($data as $variable) {
echo "$variable";
}

It shows all my form data but is missing the name of the first text box.
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

you can view individual POST elements like this:

Code: Select all

print_r($_POST['name']);
littlemetz85
Forum Newbie
Posts: 10
Joined: Mon Jul 23, 2007 5:23 pm

Post by littlemetz85 »

so is there no generic way to save the whole file no matter what the fields are. So say we update the application to have different fields then we would have to go in and change the php script?
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

I suppose you could save it as one string, and later on when you want to separate it, you could use explode or similar.

But if you add fields later on, it wont take long to amend the PHP file either.
littlemetz85
Forum Newbie
Posts: 10
Joined: Mon Jul 23, 2007 5:23 pm

Post by littlemetz85 »

That still didn't work for me. When I use:

print_r($_POST['name']);

If I use the first field on the form all that data from all the fields is printed and when I use the other fields non of the data is printed. I think the problem is that $_POST is creating an array with only one item and that one item is a string of the entire data output and is called by the first name on the form. Any ideas?
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

littlemetz85 wrote:That still didn't work for me. When I use:

print_r($_POST['name']);

If I use the first field on the form all that data from all the fields is printed and when I use the other fields non of the data is printed. I think the problem is that $_POST is creating an array with only one item and that one item is a string of the entire data output and is called by the first name on the form. Any ideas?
do you actually have an elemnet in the form with the name "name". My example required you to put in your own variable.

Eg.

Code: Select all

<input type="text" name="first_name" />
<input type="text" name="last_name" />
would have the POST data as...

Code: Select all

$_POST['first_name'];
$_POST['last_name'];
littlemetz85
Forum Newbie
Posts: 10
Joined: Mon Jul 23, 2007 5:23 pm

Post by littlemetz85 »

yea i substituted "name" with my text box name and got those results
User avatar
iknownothing
Forum Contributor
Posts: 337
Joined: Sun Dec 17, 2006 11:53 pm
Location: Sunshine Coast, Australia

Post by iknownothing »

can you post your code, including the form.
littlemetz85
Forum Newbie
Posts: 10
Joined: Mon Jul 23, 2007 5:23 pm

Post by littlemetz85 »

Sure,

The pdf is at http://littlemetz85.110mb.com/Application.pdf

and the php script is at http://littlemetz85.110mb.com/ApplicationSubmit.php

and the full file looks like:

Code: Select all

<html>

<head>
  <title></title>
</head>

<body>

<?php

echo "Name: ";
print_r ($_POST[txtName]);
echo "Address: ";
print_r ($_POST[txtAddress]);
echo "City: ";
print_r ($_POST[txtCity]);
echo "Thank You";

?>

</body>

</html>

I am using a free web server right now but it will be on a corporate server when it is done.
Post Reply