Form not sending all fields?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bleachie
    New Member
    • Feb 2008
    • 6

    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

    Code:
    function createGuestNameAndEmailElements()
                                                {
                                                    var newHTML;
                                                    newHTML='';
                                                    for (var i = 2; i <= document.getElementById('numGuests').value; i++) {
                                                        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>';
                                                    }
                                                
                                                    document.getElementById('guestNamesAndEmails').innerHTML = newHTML;
                                                    
                                                    //document.getElementById('guestNames').focus();
                                                }
    register.php
    [PHP]<?php error_reporting (0); ?>
    <?php
    include('functi on.php');
    // Receiving variables
    @$eventDate = addslashes($_PO ST['eventDate']);
    @$venueName = addslashes($_PO ST['venueName']);
    @$fullName = addslashes($_PO ST['fullName']);
    @$emailAddress = addslashes($_PO ST['emailAddress']);
    @$guestNames = addslashes($_PO ST['guestNames']);
    @$guestEmails = addslashes($_PO ST['guestEmails']);
    @$table = addslashes($_PO ST['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 = "$guestEmai ls";
    $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($_P OST['emailAddress'])==FALSE)
    {
    $errors[] = 'A valid e-mail address is required';
    }

    if(is_array($er rors))
    {
    echo '<p class="error">< b>The following errors occured</b></p>';
    while (list($key,$val ue) = 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_emai l_to", "1.Com - Guest List - $venueName", "$guestName s, $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", "$guestName s, $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,$ema ilAddress\r\n";
    $pfw_values = "$guestNames,$g uestEmails\r\n" ;
    $pfw_is_first_r ow = false;
    if(!file_exists ($pfw_file_name ))
    {
    $pfw_is_first_r ow = 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_ha ndle, $pfw_first_raw ) === FALSE) {
    die("Cannot write to file ($pfw_filename) ");
    exit;
    }
    }
    if (fwrite($pfw_ha ndle, $pfw_values) === FALSE) {
    die("Cannot write to file ($pfw_filename) ");
    exit;
    }
    fclose($pfw_han dle);
    }
    ?>[/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.
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    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.

    Comment

    • bleachie
      New Member
      • Feb 2008
      • 6

      #3
      not too sure how to do that...but i will try.

      Comment

      • bleachie
        New Member
        • Feb 2008
        • 6

        #4
        could you possible provide an example please, kinda having trouble :(

        thanks

        Comment

        • rpnew
          New Member
          • Aug 2007
          • 189

          #5
          Originally posted by bleachie
          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

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            You must make guestNames an array. You do that by specifying square brachets in the input name, like
            Code:
            name="guestNames[]"
            .Then when you e.g. enter 4 names on the form and submit, your POST-subarray looks like:
            Code:
            [guestNames] Array
                         [0] name1
                         [1] name2
                         [2] name3
                         [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=impl ode(',',$_POST['guestNames']);[/php].

            Ronald

            Comment

            • bleachie
              New Member
              • Feb 2008
              • 6

              #7
              Originally posted by ronverdonk
              You must make guestNames an array. You do that by specifying square brachets in the input name, like
              Code:
              name="guestNames[]"
              .Then when you e.g. enter 4 names on the form and submit, your POST-subarray looks like:
              Code:
              [guestNames] Array
                           [0] name1
                           [1] name2
                           [2] name3
                           [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=impl ode(',',$_POST['guestNames']);[/php].

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

              thanks alot for your help been trying for 2 days now :)

              Comment

              • Markus
                Recognized Expert Expert
                • Jun 2007
                • 6092

                #8
                Originally posted by bleachie
                is it possible to put each array in a new line? instead of showing name1,name2,nam e3

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

                Comment

                Working...