Jump to content

Form + loop thru []


Recommended Posts

Hi,

 

I now have the following but .. all variables formated as $_POST['lastname'][$i] dont hold any data, altho $total still holds the correct data?

 

case 'showtrans':

echo '<form name="trans" method="post" action="'.$_SERVER['PHP_SELF'].'?action=processtrans">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">';

$sql = mysql_query("SELECT * FROM cctrans ORDER BY firstname ASC");
while($row = mysql_fetch_array($sql)) {
foreach($row as $key=>$value){
$$key = ValidateOutput($value);
}
  	echo '<tr>
    <td width="40%">'.$firstname.' '.$lastname.' - Total = <b>$'.$total.'</b></td>
    <td width="60%">Total including freight + 4%   <input name="total[]" type="text" size="10"></td>
  	</tr>';
}

echo '<tr>
  	<td colspan="2" align="right">
<input type="hidden" name="method[]" value="'.$method.'">
<input type="hidden" name="firstname[]" value="'.$firstname.'">
<input type="hidden" name="lastname[]" value="'.$lastname.'">
<input type="hidden" name="emailaddress[]" value="'.$emailaddress.'">
<input type="hidden" name="transid[]" value="'.$transid.'">

<input type="submit" name="Submit" value="Submit">
</td>
</tr>
</table>
</form>';

break;

case 'processtrans': 

	echo '<b>Successfully emailed out the following totals including freight to:</b><br /><br />';
$sql = mysql_query("SELECT companyname, companyemail FROM company WHERE companyid = 1");
while ($row = mysql_fetch_array($sql)) {
$companyname = $row['companyname'];
$companyemail = $row['companyemail'];
}

    foreach(array_filter($_POST['total']) as $i=>$total){ 

// Set payment choice to email client
if ($_POST['method'][i] == 'Direct Credit') {
$payment = 'Please deposit the sum of: <b>$'.$total.'</b>nzd, incl gst into the following Bank Account:
<br /><br />
    $companyname
<br /><br />
    $bank
<br /><br />
    <b>Acc No:</b> $account';
}

if ($_POST['method'][i] == 'Cheque') {
$payment = 'Please post a cheque to the sum of: <strong>$'.$total.'</strong>nzd incl gst crossed and made payable to:
<br /><br />
    $companyname
<br /><br />
    $address';
}

if ($_POST['method'][i] == "Paypal") {
$payment = 'Please <a href="http://www.test.com/paypal.php?order=order&firstname='.$_POST['firstname'][i].'&lastname='.$_POST['lastname'][i].'&email='.$_POST['emailaddress'][i].'&total='.$total.'">CLICK HERE</a> to complete your order';
}

    // Mail Client 
    $headers  = "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
    $headers .= "From: $companyname <$companyemail>\r\n"; 
    $headers .= "Reply-To: $companyemail <$companyemail>\r\n"; 
    $to = "".$_POST['firstname'][$i]." ".$_POST['lastname'][$i]." <".$_POST['emailaddress'][$i].">"; 
    $subject = "$companyname order confirmation"; 

    $message = 'Hi '.$_POST['firstname'][$i].',
<br /><br />
Your new total including freight is: <b>$'.$total.'</b>
<br /><br />
'.$payment.'
<br /><br />
Regards
<br /><br />
The Team @ '.$companyname.''; 

    mail($to, $subject, $message, $headers); 

    echo ''.$_POST['firstname'][$i].' '.$_POST['lastname'][$i].' - '.$_POST['emailaddress'][$i].' '.$total.'<br />'; 
    }

 

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/94350-form-loop-thru/
Share on other sites

I noticed you had

if ($_POST['method'][i] == "Paypal") {
$payment = 'Please <a href="http://www.test.com/paypal.php?order=order&firstname='.$_POST['firstname'][i].'&lastname='.$_POST['lastname'][i].'&email='.$_POST['emailaddress'][i].'&total='.$total.'">CLICK HERE</a> to complete your order';
}

you might want to put a $'s infront of your i's,

 

For the rest I can't see why it shouldn't be showing the posted data. To be honest i don;t think you need to put you posted data into an extra array because it is only being shown once unless you validatouput function is doing something

 

Also what is it that isn;t giving you the data? is it the email or the page?

Link to comment
https://forums.phpfreaks.com/topic/94350-form-loop-thru/#findComment-483229
Share on other sites

Hi,

 

I added the $ to the i, no difference.

 

if I echo the following within the processtrans case the only result I get back is the $total variable:

 

echo ''.$_POST['firstname'][$i].' '.$_POST['lastname'][$i].' - '.$_POST['emailaddress'][$i].' '.$total.'<br />';

 

The from could hold 3 records, but I only submit totals for 2 of the records and post the form the result I get from the above echo is:

 

- 1.00

- 3.00

 

So each variable as $_POST['firstname'][$i] etc are empty.

 

I need to loop thru each record in the form and email the data from each record to the matching email address.

 

?

 

Thanks

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/94350-form-loop-thru/#findComment-483292
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.