By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,436 Members | 2,958 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,436 IT Pros & Developers. It's quick & easy.

Form not sending all fields?

P: 6
Hey,

I just need some help, my form seems to not send me all of the 'guestNames' and 'guestEmails' forms.

i use this function to add more guestnames and guestemail fields based on the number of guests added.

form.php

Expand|Select|Wrap|Line Numbers
  1. function createGuestNameAndEmailElements()
  2.                                             {
  3.                                                 var newHTML;
  4.                                                 newHTML='';
  5.                                                 for (var i = 2; i <= document.getElementById('numGuests').value; i++) {
  6.                                                     newHTML=newHTML+'<div style="float:left; left:0px; top:0px; width:100px; margin-top:5px; margin-right:10px;"><input name="guestNames" id="guestNames" type="text" value="Guest Name" class="lpWhite"  style="width:100px;"  /></div><div style="float:left; left:0px; top:0px; width:160px; margin-top:5px;"><input name="guestEmails" id="guestEmails" type="text" value="Guest Email Address" class="lpWhite"  style="width:160px;"  /></div><div style="clear:both;"></div>';
  7.                                                 }
  8.  
  9.                                                 document.getElementById('guestNamesAndEmails').innerHTML = newHTML;
  10.  
  11.                                                 //document.getElementById('guestNames').focus();
  12.                                             }  
register.php
[PHP]<?php error_reporting(0); ?>
<?php
include('function.php');
// Receiving variables
@$eventDate = addslashes($_POST['eventDate']);
@$venueName = addslashes($_POST['venueName']);
@$fullName = addslashes($_POST['fullName']);
@$emailAddress = addslashes($_POST['emailAddress']);
@$guestNames = addslashes($_POST['guestNames']);
@$guestEmails = addslashes($_POST['guestEmails']);
@$table = addslashes($_POST['table']);

//Sending auto respond Email to visitor
$pfw_header = "From: vip@1com\n"
. "Reply-To: vip@1.com\n";
$pfw_subject = "1.Com - Guest List - $venueName";
$pfw_email_to = "$emailAddress";
$pfw_message = "THIS IS NOT A CONFIRMATION EMAIL\n"
. "\n"
. "Hey $_REQUEST[fullName],\n"
. "\n"
. "If we have not responded by then please e-mail us at: Vip@1.Com with your fullname and query.\n"
. "\n"
."Venue Details:\n"
. "Date: $_REQUEST[eventDate]\n"
. "Venue: $_REQUEST[venueName]\n"
. "Table Booking: $_REQUEST[table]\n"
. "\n"
. "Your Guests:\n"
. "$_POST[guestNames]"
. "\n"
. "\n"
. "-\n"
. "Kind Regards\n"
. "The 1 Team\n"
. "---\n"
. "www.1.Com\n"
. "---\n"
. "\n"
. "The information contained in this message and any attachments is intended for the addressee only and may contain confidential and/or privileged information. If you are not the intended recipient, please destroy this message immediately. You should not copy, use or distribute this message for any purpose, nor disclose all or any part of its contents to any other person. Any views or opinions expressed in this message are those of the author and do not necessarily represent those of 1 LTD. 1 LTD disclaims any liability for any action taken in reliance on the content of this message.";

//Sending Email to form owner
$pfw_header2 = "From: $emailAddress\n"
. "Reply-To: $emailAddress\n";
$pfw_subject2 = "$eventDate - $venueName - Guest List";
$pfw_email_to2 = "vip@1.com";
$pfw_message2 = "Event Date: $_REQUEST[eventDate]\n"
. "Venue: $_REQUEST[venueName]\n"
. "Full Name: $_REQUEST[fullName]\n"
. "Email Address: $_REQUEST[emailAddress]\n"
. "Guests: \n"
. "$_POST[guestNames], $_POST[guestEmails]\n"
. "\n"
. "Table: $_REQUEST[table]\n"
. "\n"
. "Notes: \n"
. "$_REQUEST[notes]";

//Sending auto respond Email to visitor guests
$pfw_header3 = "From: vip@1.com\n"
. "Reply-To: vip@1.com\n";
$pfw_subject3 = "1.Com - Guest List - $venueName";
$pfw_email_to3 = "$guestEmails";
$pfw_message3 = "THIS IS NOT A CONFIRMATION EMAIL\n"
. "\n"
. "Hey $_REQUEST[guestNames],\n"
. "\n"
. "$_REQUEST[fullName], has used V-Parties guest list service and has added you to his guest list for:\n"
. "\n"
."Venue Details:\n"
. "Date: $_REQUEST[eventDate]\n"
. "Venue: $_REQUEST[venueName]\n"
. "\n"
. "Your Guests:\n"
. "$_POST[guestNames]"
. "\n"
. "\n"
. "-\n"
. "Kind Regards\n"
. "The 1 Team\n"
. "---\n"
. "www.1Com\n"
. "---\n"
. "\n"
. "The information contained in this message and any attachments is intended for the addressee only and may contain confidential and/or privileged information. If you are not the intended recipient, please destroy this message immediately. You should not copy, use or distribute this message for any purpose, nor disclose all or any part of its contents to any other person. Any views or opinions expressed in this message are those of the author and do not necessarily represent those of 1 LTD. 1 LTD disclaims any liability for any action taken in reliance on the content of this message.";


/* Validation */


if ($_POST['fullName']=='' || alpha_numeric($_POST['fullName'])<3)
{
$errors[] = 'A fullname is required and be more than 3 characters';
}

if ($_POST['numGuests']=='' || valid_guests($_POST['numGuests'])<2)
{
$errors[] = 'A number of guests must be over 2';
}

if ($_POST['emailAddress']=='' || valid_email($_POST['emailAddress'])==FALSE)
{
$errors[] = 'A valid e-mail address is required';
}

if(is_array($errors))
{
echo '<p class="error"><b>The following errors occured</b></p>';
while (list($key,$value) = each($errors))
{

echo '<span class="error">'.$value.'</span><br />';
}
}
else {
echo '<p><b>Success!</b></p>';
echo '<span>Your guest list was successfully processed. A confirmation email has been sent to your email mailbox.</span>';

//send e-mails
mail("$pfw_email_to", "1.Com - Guest List - $venueName", "$guestNames, $pfw_message", "From: vip@1.com", "-f"."vip@1.com");
mail("vip@1.com", "$eventDate - $venueName - Guest List", "$pfw_message2", "From: $_REQUEST[emailAddress]", "-f".$_REQUEST[emailAddress]);
mail("$_POST[guestEmails]", "1.Com - Guest List - $venueName", "$guestNames, $pfw_message3", "From: vip@1.com", "-f"."vip@1.com");

//saving record in a text file
$pfw_file_name = "Data.csv";
$pfw_first_raw = "Fullname,Email\r\n";
$pfw_values = "$fullName,$emailAddress\r\n";
$pfw_values = "$guestNames,$guestEmails\r\n";
$pfw_is_first_row = false;
if(!file_exists($pfw_file_name))
{
$pfw_is_first_row = true ;
}
if (!$pfw_handle = fopen($pfw_file_name, 'a+')) {
die("Cannot open file ($pfw_file_name)");
exit;
}
if ($pfw_is_first_row)
{
if (fwrite($pfw_handle, $pfw_first_raw ) === FALSE) {
die("Cannot write to file ($pfw_filename)");
exit;
}
}
if (fwrite($pfw_handle, $pfw_values) === FALSE) {
die("Cannot write to file ($pfw_filename)");
exit;
}
fclose($pfw_handle);
}
?>[/PHP]

now the problem is, if i choose 4 guests in the field and the form generates for me 4 fields to fill in.

only the last field's information will show in the email sent.

if anyone could help out that would be great.

Thanks.
Mar 14 '08 #1
Share this Question
Share on Google+
7 Replies


TheServant
Expert 100+
P: 1,168
It's because if you generate 4 fields, they are all having the same id (and name), so when it is sent to the form handler, it will only take the latest id (which will always be thelast field with that id).

What you need to do is change your form generation to also increment the id's and name's of each field.
Mar 14 '08 #2

P: 6
not too sure how to do that...but i will try.
Mar 14 '08 #3

P: 6
could you possible provide an example please, kinda having trouble :(

thanks
Mar 14 '08 #4

rpnew
100+
P: 188
could you possible provide an example please, kinda having trouble :(

thanks
Hi,
You can use Array for name attribute to get all the values on other page...
simply make name="somearray[]".. and on the next page use foreach loop to get their values...

Regards,
RP
Mar 14 '08 #5

ronverdonk
Expert 2.5K+
P: 4,258
You must make guestNames an array. You do that by specifying square brachets in the input name, like
Expand|Select|Wrap|Line Numbers
  1. name="guestNames[]"
.Then when you e.g. enter 4 names on the form and submit, your POST-subarray looks like:
Expand|Select|Wrap|Line Numbers
  1. [guestNames] Array
  2.              [0] name1
  3.              [1] name2
  4.              [2] name3
  5.              [3] name4
The same applies of course to the addresses.

One way of getting the names out is in case you want all names in one 'to' string is to implode the array like this[php]$to_string=implode(',',$_POST['guestNames']);[/php].

Ronald
Mar 14 '08 #6

P: 6
You must make guestNames an array. You do that by specifying square brachets in the input name, like
Expand|Select|Wrap|Line Numbers
  1. name="guestNames[]"
.Then when you e.g. enter 4 names on the form and submit, your POST-subarray looks like:
Expand|Select|Wrap|Line Numbers
  1. [guestNames] Array
  2.              [0] name1
  3.              [1] name2
  4.              [2] name3
  5.              [3] name4
The same applies of course to the addresses.

One way of getting the names out is in case you want all names in one 'to' string is to implode the array like this[php]$to_string=implode(',',$_POST['guestNames']);[/php].

Ronald
is it possible to put each array in a new line? instead of showing name1,name2,name3

thanks alot for your help been trying for 2 days now :)
Mar 14 '08 #7

Markus
Expert 5K+
P: 6,050
is it possible to put each array in a new line? instead of showing name1,name2,name3

thanks alot for your help been trying for 2 days now :)
try
[php]
foreach($_POST['guestNames'] as $_key => $_value)
{
echo "$_key - $_value<br />";
}
[/php]
Mar 14 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.