473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Form not sending all fields?

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
7 3303
TheServant
1,168 Expert 1GB
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
not too sure how to do that...but i will try.
Mar 14 '08 #3
could you possible provide an example please, kinda having trouble :(

thanks
Mar 14 '08 #4
rpnew
188 100+
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
4,258 Expert 4TB
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
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
6,050 Expert 4TB
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

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

Similar topics

3
by: TekWiz | last post by:
I've got a system that automatically generates a form. I have it set up so that the backend will return to the inital form page with an error object in sessions data (assuming the backend detected...
7
by: Dave B | last post by:
Does anyone know of a program that will read a text file and fill in a web form with the contents of that file? We need to get about 3000 records (5 fields to each record) into a database owned by...
3
by: shortbackandsides.no | last post by:
I've been having trouble preventing users pressing Enter part way down a form so the incomplete form gets submitted. I came up with a possible solution - the code below seems to work in both...
2
by: sfriedman | last post by:
I was able to successfully link my Outlook Contacts table to an Access Database and create an entry form. Unfortunately the Displayname field which is one of the key fields for how the contact is...
6
by: Salad | last post by:
Hi: I have a Bill of Lading template from the printer that I saved as a BMP. I created a new report and in the report's picture property told it the BMP file name. It brought the image in just...
3
by: Chris Baker | last post by:
This is a problem I have been troubleshooting for about 4-6 months. I have an e-mail form on a client's public website that is mis-behaving. It is written in ASP and uses a CDO.Message object. ...
27
by: Scott | last post by:
I've been trying to come up with a way to ensure user input is coming from the form on my site, and not auto-submitted from elsewhere, and I don't want to use the "enter the code shown in the...
7
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form...
1
by: starter08 | last post by:
Hi, I have a C++ routine(client-side) which uploads an xml file to a web server by making a socket connection and sending all the post request through that socket. On the server side I have a cgi...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.