can anyone here maybe help me with this, posting data gathered from php to an xml file please?
AnimeGalleries [dot] Net | AnimeWallpapers [dot] Com | AnimeLyrics [dot] Com | AnimePedia [dot] Com | AnimeGlobe [dot] Com |
can anyone here maybe help me with this, posting data gathered from php to an xml file please?
Millionaire Campaign:
Making millionaires out of everyone
This was unknowingly
brought to you
by .Elmer
and knowingly
sponsored by Baka Baka!!!
avi made by my sweet cousin .Elmer
I'm not sure I understand what you are asking ... do you mean using PHP to generate an XML file?
There is a way to post XML data from PHP, maybe this would help, but i'm not sure of exactly what you're trying to do.
月の光は愛のメッセージ
hmmm I'm not really sure my boss wants this done, he didn't really give me any details, but the conclusion I came to is he wants me to take data gatherd from a post page, a page where we gather data from clients like name, surname, id number, eamil address etc. and put that into xml format and then link it to a URL given to us by the sponsor on a remote server. I know this all sounds pretty confusing but I myslef don't really get whats going on.
Millionaire Campaign:
Making millionaires out of everyone
This was unknowingly
brought to you
by .Elmer
and knowingly
sponsored by Baka Baka!!!
avi made by my sweet cousin .Elmer
Okay I tried the code miss moonlight linked me too, but I don't quite understand how it works. I have never done XML before and I have no idea how to use it, my boss wants me to take the information from this page
https://www.ratesdirect.co.za/insura...ontactform.php
and then post it in a xml format that's suppose to go to this link https://www.outsurance.co.za/OLL/goleadtest.asp
Last edited by IFS; 10-06-2009 at 01:58 AM.
Millionaire Campaign:
Making millionaires out of everyone
This was unknowingly
brought to you
by .Elmer
and knowingly
sponsored by Baka Baka!!!
avi made by my sweet cousin .Elmer
I'm assuming the "xmlcontactform.php" script is the one you are building.
I'll make an example of the script for the first entry(first name):
Then it's up to your client to link his "goleadtest.asp" script to your XML file.PHP Code:
<?php
// when you press the submit button this part is processed
if( $_REQUEST['action'] == "xml" )
{
// this is where we add the gathered data from the form below
$xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
$xml .= "<CustomerData>\n\t<FirstName>" . $_POST['firstname'] . "</FirstName>\n</CustomerData>";
// this is a function that will save the content to a normal XML file
saveToFile($xml);
}
// this prints the form as you have it on your site (only the first name though)
print "<html>
<body>
<form action=\"$PHP_SELF?action=xml\" method=\"post\" enctype=\"multipart/form-data\">
<input type=\"text\" name=\"firstname\"><p>
<input type=\"submit\" value=\"Submit\">
</form>
</body>
</html>
";
?>
cURL is a function when you have to gather data from another site and in your situation can't help you.
Hope this helps you a little. ^_^
Last edited by FlashD; 10-06-2009 at 04:49 PM. Reason: Fixed the typo
thanks alot man, all this is greatly appreciated
ps. I just tried the code you gave me in a test page and I got this error
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /usr/wwws/users/ratesg/insurance/carinsurance/test.php on line 7
I have no idea what this means.
Last edited by IFS; 10-06-2009 at 07:29 AM.
Millionaire Campaign:
Making millionaires out of everyone
This was unknowingly
brought to you
by .Elmer
and knowingly
sponsored by Baka Baka!!!
avi made by my sweet cousin .Elmer
My code doesn't work as is. I wrote it only as an example. It's missing the function saveToFile() which writes the data into a file.
The error shown is because of this line
It should be:PHP Code:
$xml .= "<CustomerData>\n\t<FirstName>$_POST['firstname']</FirstName>\n</CustomerData>";
Just to see if the XML works use this one:PHP Code:
$xml .= "<CustomerData>\n\t<FirstName>".$_POST['firstname']."</FirstName>\n</CustomerData>";
PHP Code:
<?php
// when you press the submit button this part is processed
if( $_REQUEST['action'] == "xml" )
{
// this is where we add the gathered data from the form below
$xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
$xml .= "<CustomerData>\n\t<FirstName>${_POST['firstname']}</FirstName>\n</CustomerData>";
// this is a function that will save the content to a normal XML file
print $xml;
die();
}
// this prints the form as you have it on your site (only the first name though)
print "<html>
<body>
<form action=\"$PHP_SELF?action=xml\" method=\"post\" enctype=\"multipart/form-data\">
<input type=\"text\" name=\"firstname\"><p>
<input type=\"submit\" value=\"Submit\">
</form>
</body>
</html>
";
?>
thanks for all the help with this, I have another question, what if I create and xml file with empty fields you know just <firstname></firstname> etc. and then by clicking the continue button it adds the data to the xml file and then sends it to the link I got
Millionaire Campaign:
Making millionaires out of everyone
This was unknowingly
brought to you
by .Elmer
and knowingly
sponsored by Baka Baka!!!
avi made by my sweet cousin .Elmer
You can do that, but it will just make things more complex, because you will have to write a function that is able to read your empty file. My suggestion is to hardcode the fields as I showed you and then make a saveToFile() function that reads the already created XML file (so the old data are not overwritten) and adds the new data to it.
Last edited by FlashD; 10-07-2009 at 03:36 PM.
Sounds like a really awkward solution. In general, temp files and web programming do not go well together. Not only will you get uniqueness problems (what if two users simultaneously use the form? this is solvable, but it's gonna be ugly). A bigger problem is, what if the user doesn't hit submit? Then a temporary file will litter your server forever.
Hey look, Japan made a movie about me!
Eris has a point here. If two sessions write to the file at the same time one of the two will be lost. To avoid this, the best way is to use a database. You can use two PHP files, one that writes to the DB, while the other works as an XML builder, which gets this data from the DB and outputs it in XML format. This second script would also work as the file the second server links to.
Last edited by FlashD; 10-07-2009 at 04:46 PM.
okay but only my boss will use that form, he gets info from people and manually input them into that form and from there he sends it to the link given to us from our clients (if that makes sense) so there will only be one person at a time who would use that form.
ps.
quick question how do you set the minimum value of an input type="text" field in html, I tried but my methods aren't working
Last edited by IFS; 10-08-2009 at 03:38 AM.
Millionaire Campaign:
Making millionaires out of everyone
This was unknowingly
brought to you
by .Elmer
and knowingly
sponsored by Baka Baka!!!
avi made by my sweet cousin .Elmer
In that case use my first solution.
As for your other question you can't. The min value for an input element cannot be set. You can use PHP to do the trick though:
PHP Code:
// returns the message and stops the script if the length is not above 6 characters
if( strlen($_POST['firstname']) < 6 )
{
echo "Your first name is not long enough. Go tell your government you want a name change. :P";
die();
}
Last edited by FlashD; 10-08-2009 at 07:33 AM.
Of course you can, with javascript. You should still do the above in case the user doesn't have javascript enabled, or uses some weird browser, but on top of that, you can add a javascript that does client-side validation to save server processing power on requests.
I don't have my good DOM programming book around, but I think that approach should be pretty safe and fail gracefully where it doesn't work.Code:<html> <head> <script language="javascript"> function validate_form() { var name = document.getElementById('name'); // Silently deal with errors: if(name == null) return true; // Go on with with submit // Check name length if(name.value.length < 5) { alert("Name must be longer than 5 letters"); return false; // Do not go on with submit } else return true; // Go on with submit } </script> </head> <body> <form id="myform" onSubmit="return validate_form();" method="POST" action="whatever"> <input type="text" id="name"></input> <input type="submit"></input> </form> </body> </html>
Last edited by Eris; 10-08-2009 at 12:23 PM.
Hey look, Japan made a movie about me!
Thanks for all the help FlashD and Eris, and Miss Moonlight its all greatly appreciated
Millionaire Campaign:
Making millionaires out of everyone
This was unknowingly
brought to you
by .Elmer
and knowingly
sponsored by Baka Baka!!!
avi made by my sweet cousin .Elmer
this is really good code, but how would I use it?
The method I used it in is as a post page, you enter info in the contactform and it gets posted automatically to the xml page, but this give me a new form where I then have to enter in data again, and then it takes me to the xml page, here is a link to see what I mean https://www.ratesdirect.co.za/insura...r/xml-gate.php how do I get the xml file it posts to as a file on my computer or get it to mail the xml page to me?
Millionaire Campaign:
Making millionaires out of everyone
This was unknowingly
brought to you
by .Elmer
and knowingly
sponsored by Baka Baka!!!
avi made by my sweet cousin .Elmer
I checked your site and you just redirected your form to mine and this is not what I meant. You have to edit my form to match yours and join them.
You have to take my script and include it somewhere in your own script and change this part:
in my script with yours. The action attribute in the form element needs to be the same as mine though.HTML Code:<html> <body> <form action=\"$PHP_SELF?action=xml\" method=\"post\" enctype=\"multipart/form-data\"> <input type=\"text\" name=\"firstname\"><p> <input type=\"submit\" value=\"Submit\"> </form> </body> </html>
I did change that part, and it didn't give me any display, so I changed it back before I posted the link, because I thought I might have messed something up
Millionaire Campaign:
Making millionaires out of everyone
This was unknowingly
brought to you
by .Elmer
and knowingly
sponsored by Baka Baka!!!
avi made by my sweet cousin .Elmer
PM me the PHP file with the form you are using and I'll see if I can help you with it a little more. Like that my hands are pretty much tied.
thanks FlashD much appreciated, just one noob question from my side, how does one upload files to a private message? I tried earlier today but I couldn't find a place where I could do that
Millionaire Campaign:
Making millionaires out of everyone
This was unknowingly
brought to you
by .Elmer
and knowingly
sponsored by Baka Baka!!!
avi made by my sweet cousin .Elmer
Change the extension of your script from .php to .phps and PM me the link to it. I will look at it only after tomorrow, since I won't be home tomorrow. You can't upload files via PMs, btw.
Last edited by FlashD; 10-13-2009 at 03:58 PM.
I'm sorry this must be getting annoying, but this is what need to be done
Required Fields:
-Title
-Firstname
-Lastname
-ID
-We also need at least 1 contact number.
Validation:
-No numeric or special characters to be sent through firstname or lastname.
-ID must have 13 numeric values no letters or special characters.
-Contact number must be numeric and not have special characters or spaces.
- Telephone number. The area code must be 3 digits and number must be 7.
- Mobile number must be 10 digits.
-Email must only allow @_.- to be accepted no other special characters.
XML, replace VALUES as required.
<?xml version="1.0" encoding="UTF-8"?>
<lead>
<mode>TEST</mode> keep as TEST only change if directed
<title>TITLE</title> Mr, Mrs, Miss, Dr, Prof are the only values we currently accept
<firstname>FIRSTNAME</firstname>
<lastname>LASTNAME</lastname>
<id>ID</id> Will help with validation and reducing duplicate leads
<homecode>HOMECODE</homecode>
<hometel>HOMETEL</hometel>
<workcode>WORKCODE</workcode>
<worktel>WORKTEL</worktel>
<mobile>MOBILE</mobile>
<email>EMAIL</email>
<comment>COMMENT</comment>
<source>RATESDIRECT</source> This identifies your source
<notes></notes> Leave blank
<language>E</language> E – English (default), A – Afrikaans
<product>PRODUCT</product> P – Personal (Default), B – Business
</lead>
The above XML can then be posted to https://www.outsurance.co.za/OLL/goleadtest.asp a XML response will be then be returned.
The XML should be posted in a variable called lead and the XML also needs to be URLencoded.
<?xml version="1.0" encoding="UTF-8"?>
<response>
<resultNo><resultNo> -1 if an error occurred. 0 is successful
<resultMsg></resultMsg> On success returns reference number for the lead generated.
</response>
These are the possible returned values for resultMsg
^
is what should happen or whatever. I'm really sorry for asking so much help but I have no idea what the hell I'm suppose to do here
Millionaire Campaign:
Making millionaires out of everyone
This was unknowingly
brought to you
by .Elmer
and knowingly
sponsored by Baka Baka!!!
avi made by my sweet cousin .Elmer
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks