Jump to content

php form


chriscloyd

Recommended Posts

heres my problem when i retrive the form with my php script its not showing multiple services from the services field so if i select more than one its not working it will only show the top one
how do i fix it ?

heres my form
[code]
<form id="form1" name="form1" method="post" action="includes/send_quote.php">
          <table width="253" border="0" cellspacing="5" cellpadding="0">
    <tr>
      <td valign="middle"><div align="right" class="style17">First Name</div></td>
      <td><div align="center" class="style17">*</div></td>
      <td><input name="FirstName" type="text" class="input2" id="FirstName" /></td>
    </tr>
    <tr>
      <td valign="middle"><div align="right" class="style17">Last Name </div></td>
      <td><div align="center" class="style17">*</div></td>
      <td><input name="LastName" type="text" class="input2" id="LastName" /></td>
    </tr>
    <tr>
      <td valign="middle"><div align="right" class="style17">Phone # </div></td>
      <td><div align="center" class="style17">*</div></td>
      <td><input name="PhoneNumber" type="text" class="input2" id="PhoneNumber" /></td>
    </tr>
    <tr>
      <td valign="middle"><div align="right" class="style17">Email</div></td>
      <td><div align="center" class="style17">*</div></td>
      <td><input name="EmailAddress" type="text" class="input2" id="EmailAddress" /></td>
    </tr>
    <tr>
      <td valign="middle"><div align="right" class="style17">Budget </div></td>
      <td><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td>
      <td><span class="style17">
        <label>
          <select name="budget" id="budget">
            <option value="&lt; $100">&lt; $100</option>
            <option value="$100 - $200" selected>$100 - $200</option>
            <option value="$200 - $300">$200 - $300</option>
            <option value="$300 - $400">$300 - $400</option>
            <option value="$400 - $500">$400 - $500</option>
            <option value="$500 - $600">$500 - $600</option>
            <option value="$600 - $700">$600 - $700</option>
            <option value="$700 - $800">$700 - $800</option>
            <option value="$800 - $900">$800 - $900</option>
            <option value="$800 - $900">$800 - $900</option>
            <option value="$1000 - $2000">$1000 - $2000</option>
            <option value="$2000 - $3000">$2000 - $3000</option>
            <option value="$3000+">$3000+</option>
          </select>
        </label>
      </span></td>
    </tr>
    <tr>
      <td valign="middle"><div align="right" class="style17">URL</div></td>
      <td><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td>
      <td><input name="url" type="text" class="input2" id="url" /></td>
    </tr>
    <tr>
      <td width="60" rowspan="2" valign="top"><div align="right" class="style17">Service</div>
        <span class="style17">Use Ctrl
to select
more than one</span></td>
      <td valign="top"><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td>
      <td width="164" rowspan="2" valign="top"><span class="style17">
        <select name="services" size="4" multiple="multiple" id="services">
          <option value="Web Desgin">Web Desgin</option>
          <option value="Logo/Branding Design">Logo/Branding Design</option>
          <option value="Web Development">Web Development</option>
          <option value="Other">Other</option>
        </select>
      </span></td>
    </tr>
    <tr>
      <td valign="top"><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td>
    </tr>
    <tr>
      <td valign="middle"><div align="right" class="style17">If Other </div></td>
      <td><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td>
      <td><input name="other2" type="text" class="input2" id="other2" /></td>
    </tr>
    <tr>
      <td valign="middle"><div align="right" class="style17">Description</div></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td colspan="3"><div align="center" class="style17">
        <textarea name="description" cols="25" rows="5" class="style21" id="description"></textarea>
      </div></td>
    </tr>
    <tr>
      <td><div align="right" class="style17">Refered By </div></td>
      <td>&nbsp;</td>
      <td><span class="style17">
        <select name="refered">
          <option value="">Select One</option>
          <?php
$sales = mysql_query("select * from users where level in ('sales','admin') order by first, last asc");
while ($s = mysql_fetch_assoc($sales)) {
echo '<option value="'.$s['id'].'">'.$s['first'].' '.$s['last'].'</option>';
}
?>
        </select>
      </span> </td>
    </tr>
    <tr>
      <td width="60"><input name="date" type="hidden" value="<?php echo date("n/j/Y g:i:s A"); ?>" /></td>
      <td width="9"><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td>
      <td width="164"><span class="style17">
        <label>
          <input name="Submit" type="submit" class="input" onClick="MM_validateForm('FirstName','','R','LastName','','R','PhoneNumber','','RisNum','EmailAddress','','RisEmail');return document.MM_returnValue" value="Get Quote" />
          </label>
      </span></td>
    </tr>
  </table>
</form>
[/code]
Link to comment
Share on other sites

try this instead for the service line:

[code]<select name="services[]" size="4" multiple="multiple" id="services">[/code]

what is happening is each one you select is over-writing the previous one, but if you make the name an array then when it is passed to php it becomes an array and you can retrive values much as jesirose said
Link to comment
Share on other sites

That's what print_r does.

Is test the only input you are using when you fill out the form? It really should be printing out much more than that if you print_r($_POST); <-- exactly like that.

You're seriously not getting other fields like your hidden ones? That seems...rather improbable.
Link to comment
Share on other sites

Okay, you're missing the point.
You said "when i retrive the form with my php script its not showing multiple services from the services field"

Now, you have your multiple services. I guess you used test instead of services. When you process it, services is an array because there are multiple values.

Now if you want to do something with that array, use foreach instead of print_r. Print_r was to make sure the values were being set.

Your initial problem has been solved...
Link to comment
Share on other sites

Got it!

Ignore the implode, i'll give ut he workign code, one moment.

[code]<form id="form1" name="form1" method="post" action="myTest1.php">
          <table width="253" border="0" cellspacing="5" cellpadding="0">
    <tr>
      <td valign="middle"><div align="right" class="style17">First Name</div></td>
      <td><div align="center" class="style17">*</div></td>
      <td><input name="FirstName" type="text" class="input2" id="FirstName" /></td>
    </tr>
    <tr>
      <td valign="middle"><div align="right" class="style17">Last Name </div></td>
      <td><div align="center" class="style17">*</div></td>
      <td><input name="LastName" type="text" class="input2" id="LastName" /></td>
    </tr>
    <tr>
      <td valign="middle"><div align="right" class="style17">Phone # </div></td>
      <td><div align="center" class="style17">*</div></td>
      <td><input name="PhoneNumber" type="text" class="input2" id="PhoneNumber" /></td>
    </tr>
    <tr>
      <td valign="middle"><div align="right" class="style17">Email</div></td>
      <td><div align="center" class="style17">*</div></td>
      <td><input name="EmailAddress" type="text" class="input2" id="EmailAddress" /></td>
    </tr>
    <tr>
      <td valign="middle"><div align="right" class="style17">Budget </div></td>
      <td><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td>
      <td><span class="style17">
        <label>
          <select name="budget" id="budget">
            <option value="&lt; $100">&lt; $100</option>
            <option value="$100 - $200" selected>$100 - $200</option>
            <option value="$200 - $300">$200 - $300</option>
            <option value="$300 - $400">$300 - $400</option>
            <option value="$400 - $500">$400 - $500</option>
            <option value="$500 - $600">$500 - $600</option>
            <option value="$600 - $700">$600 - $700</option>
            <option value="$700 - $800">$700 - $800</option>
            <option value="$800 - $900">$800 - $900</option>
            <option value="$800 - $900">$800 - $900</option>
            <option value="$1000 - $2000">$1000 - $2000</option>
            <option value="$2000 - $3000">$2000 - $3000</option>
            <option value="$3000+">$3000+</option>
          </select>
        </label>
      </span></td>
    </tr>
    <tr>
      <td valign="middle"><div align="right" class="style17">URL</div></td>
      <td><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td>
      <td><input name="url" type="text" class="input2" id="url" /></td>
    </tr>
    <tr>
      <td width="60" rowspan="2" valign="top"><div align="right" class="style17">Service</div>
        <span class="style17">Use Ctrl
to select
more than one</span></td>
      <td valign="top"><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td>
      <td width="164" rowspan="2" valign="top"><span class="style17">
        <select name="services[]" size="4" id="services" multiple>
          <option value="Web Design">Web Design</option>
          <option value="Logo/Branding Design">Logo/Branding Design</option>
          <option value="Web Development">Web Development</option>
          <option value="Other">Other</option>
        </select>
      </span></td>
    </tr>
    <tr>
      <td valign="top"><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td>
    </tr>
    <tr>
      <td valign="middle"><div align="right" class="style17">If Other </div></td>
      <td><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td>
      <td><input name="other2" type="text" class="input2" id="other2" /></td>
    </tr>
    <tr>
      <td valign="middle"><div align="right" class="style17">Description</div></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td colspan="3"><div align="center" class="style17">
        <textarea name="description" cols="25" rows="5" class="style21" id="description"></textarea>
      </div></td>
    </tr>
    <tr>
      <td><div align="right" class="style17">Refered By </div></td>
      <td>&nbsp;</td>
      <td><span class="style17">
        <select name="refered">
          <option value="">Select One</option>
          <?php
$sales = mysql_query("select * from users where level in ('sales','admin') order by first, last asc");
while ($s = mysql_fetch_assoc($sales)) {
echo '<option value="'.$s['id'].'">'.$s['first'].' '.$s['last'].'</option>';
}
?>
        </select>
      </span> </td>
    </tr>
    <tr>
      <td width="60"><input name="date" type="hidden" value="<?php echo date("n/j/Y g:i:s A"); ?>" /></td>
      <td width="9"><div align="center"><span class="style8"><span class="style8"><span class="style11"><span class="style19"></span></span></span></span></div></td>
      <td width="164"><span class="style17">
        <label>
          <input name="Submit" type="submit" class="input" onClick="MM_validateForm('FirstName','','R','LastName','','R','PhoneNumber','','RisNum','EmailAddress','','RisEmail');return document.MM_returnValue" value="Get Quote" />
          </label>
      </span></td>
    </tr>
  </table>
</form>
[/code]


Receiving page is this to print out just those values in the services array:

[code]<?php

if(isset($_POST['services'])){

    $a = $_POST['services'];
         
          foreach($a as $b) {
 
              $c .= $b.'<br />';
          }
echo $c;
}

else {

echo "not set";

}

?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.