Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing PHP array to Perl 1

Status
Not open for further replies.

stmosaic

IS-IT--Management
Nov 10, 2004
10
US
I'm very weak in Perl/PHP, spent the last 2 days figuring out passing multiple checkboxes to a PHP page and was able to figure it out with some help from online tutorials. But now I'm stuck, I've searched for any working solutions similar to my dilemma: how to pass the dynamic PHP array to Perl for emailing. The code doesn't throw any errors, but it doesn't send the info either - seems like the variables aren't being passed or not being read. Here is the code from the PHP form page:
<code>
<?php

foreach($_POST['ptitle'] as $key => $ptitle) {
print("<br><input type=\"checkbox\" name=\"ptitle[]\" value=\"$ptitle\" checked>" . $ptitle);
}

?>
</code>
This is the code from within a subroutine on my .pl page that emails the form contents:
<code>
print MAIL "PROPERTIES OF INTEREST: ";
foreach $ptitle (@ptitle)
{
print "$value ", "\n";
}
</code>
I've looked for any similar solutions and read perl books, but all it's maganged to do is confuse me even more! If I had a choice, I'd rewrite the .pl email in PHP, but that is not an option, so I need to make these 2 pages play nice together. I would appreciate any help you Perl and PHP experts can give me on this!
 
How are you passing the values from the PHP page in to the perl script?

--Paul

Nancy Griffith - songstress extraordinaire,
and composer of the snipers anthem "From a distance ...
 
do you not have to use the param() method to collect form contents into a CGI script? Plus you shouldn't be giving all the checkboxes the same name really. i.e.
Code:
$ptitle1 = param("ptitle1");


Rob Waite
 
Paul,
I thought I was passing the values through the form upon submittal since the PHP is rendering the array of choices into html on that first page example. Here's what the php renders:
<code>
<input type="checkbox" name="ptitle[]" value="Farmington Villas" checked>Farmington Villas<br>
<input type="checkbox" name="ptitle[]" value="6126 Winged Foot Court-Under Contract!" checked>6126 Winged Foot Court-Under Contract!<br>
<input type="checkbox" name="ptitle[]" value="6124 Greenbriar Drive" checked>6124 Greenbriar Drive
</code>
Pardon my ignorance, I'm used to CF programming. Getting a slight handle on the PHP, but the Perl is making my head spin! :)

Rob,

Told you I was very weak in Perl, classes 3 years ago and haven't used it since. Ok, I can see the need for the param() from the other sections of the code I'm working on. As far as not using the same name for the checkboxes, they are dynamically generated with PHP and the number of them will vary depending on the user's choices. So, I guess I'm not seeing how they can be anything but the same or how to get around that not so little problem.

Thank you both for taking the time to help me out!
 
Code:
<input type="checkbox" name="ptitle_1" value="Farmington Villas" checked>Farmington Villas<br>
<input type="checkbox" name="ptitle_2" value="6126 Winged Foot Court-Under Contract!" checked>6126 Winged Foot Court-Under Contract!<br>
<input type="checkbox" name="ptitle_3" value="6124 Greenbriar Drive" checked>6124 Greenbriar Drive

Is how I would normally do it, I'm not sure how PHP passes arrays. Another thing is to have a javascript routine pack the values into a delimited string, and unpack it at the other end

Code:
use CGI;
$q=new CGI;
foreach ($q->param()) {
       eval ("$_ = $q->param($_);");
       $thisvar=$_;
       if (index ($thisvar, "ptitle") != -1) {
          ($pt,$index)= split (/_/, $thisvar);
          $ptitle[$index]=$q->param($thisvar);
       }
}

I know there's a much more elegant solution, but this or something very like it worked for me in the past.

--Paul

HTH
--Paul


Nancy Griffith - songstress extraordinaire,
and composer of the snipers anthem "From a distance ...
 
There's absolutely nothing wrong with giving your checkboxes the same name and this is, in fact, supported by CGI.pm.

Code:
my @ptitles = $q->param('ptitle[]');

AFAIK, PHP requires you to put those [] after the input name in order for it to give an array of values. Perl's CGI module has no such limitation so you can call them all 'ptitle' and then do a $q->param('ptitle') to get the values.
 
Why not just use PHP to handle the mailing?


haunter@battlestrata.com
 
Haunter,

The perl part already exists and is used for routing and other purposes. I was trying to help my employer and become familiar with PHP. I've had to pass this project on to our perl consultant to finish, it was taking me waaay too long to figure out. For my next attempt, I'm just going to start from scratch with PHP, it makes more sense to me. Thank you everyone for the great help, especially Paul & ishnid!!
 
Perl is wayyy more powerful than PHP in that you don't need a web envorinment to run it, it's worth the effort

--Paul

Nancy Griffith - songstress extraordinaire,
and composer of the snipers anthem "From a distance ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top