 | Generating a HTTP POST request with dynamic contentsI find the following code sample on how to generate a HTTP POST with multipart/form-data encoding; however, in my case, I won't know which parameters are available until runtime. For example, I may have only 'name' and 'email'. Is there a way I can work around it and provide a dynamic list of parameters? Thanks.
POST 'http://www.perl.org/survey.cgi',
Content_Type => 'form-data',
Content => [ name => 'Gisle Aas',
email => 'gisle@aas.no',
gender => 'M',
born => '1964',
init => ["$ENV{HOME}/.profile"],
]
|
|
 Jafo232You Can't Spell Democrat Without Rat.Premium join:2002-10-17 Boonville, NY | You mean something like this?
POST $url,
Content_Type => 'form-data',
Content => [ name => $name,
email => $email,
gender => $gender,
born => $dob,
init => ["$ENV{HOME}/.profile"],
]
-- Custom PHP/Perl Development. Vbulletin And Wordpress Mods Too! |
|
|
|
 JAAuldeWeb DeveloperPremium,MVM join:2001-05-09 Hagerstown, MD kudos:3 | reply to httppost We'll really need a little more context as to the data structures you'll be working with. |
|
 | reply to httppost No, I don't know how many items I will have for Content. For example, I may have "name" and "email" only, but "gender", "born" and "init" won't be available. The script need to be flexible enough to handle unknown number of contents. |
|
 Tenar join:2008-01-02 Midland, ON | reply to httppost Can you use a foreach loop and test for possible keys? |
|
 Reviews:
·Comcast
| reply to httppost You trying to do like facebook(i think) or something, click the link that then shows the next field if you want it? IE: name: Email:
link-add your address link-add your website
If thats what your doing, Id just render them all to the page, just display:none, and give the fields the database column names so you could do a foreach like suggested. Something like
foreach($_POST as $k=>$v){
if(!empty($v)) $sql = '`'.$k.'`="'.$v.'",';
}
If the fields are dynamica nd the user can make them, its all in your db. There needs to be a table for form and then elements.
-- Connecticut Web Design and Development |
|
 Jafo232You Can't Spell Democrat Without Rat.Premium join:2002-10-17 Boonville, NY | In the above example, don't forget to sanitize $k and $v.. |
|
 | reply to httppost Yup and it would be $sql.=whatever or it would just keep rewriting. |
|