processing multiple textfields with php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
njm
Forum Newbie
Posts: 2
Joined: Tue Dec 29, 2009 2:48 pm

processing multiple textfields with php

Post by njm »

Hello,

I'm new to PHP and I have 2 questions about processing an HTML form.

1. I'm building a PHP site and I have a form that uses 3 text input fields to capture a phone number, so a field for the area code, and 2 fields for the other parts of the number. I want to store the whole phone number in a single field in MySQL. My question is how can I get the $_POST array to store only my concatenation of the whole phone number, and delete the 3 elements that represent each text input field for the phone number?

Also,

2. How can I make a sticky selection list? I have selection lists that store the 50 states and some years for birthdates. I want to preserve those selections if someone is brought back to the form due to an input error. I know there's a way to do it, but I haven't figured it out.

I'm using Windows XP, PHP 5, MySQL 5, and Internet Explorer. I'm coding in Dreamweaver.

Thank you very much,

Nick
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: processing multiple textfields with php

Post by AbraCadaver »

1. If there are three inputs then you get three items in the $_POST array. You would concatenate them on the resulting page:

Code: Select all

$phone_num = $_POST['field1'] . $_POST['field2'] . $_POST['field3'] ;
2. We'll need some code to tell.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
njm
Forum Newbie
Posts: 2
Joined: Tue Dec 29, 2009 2:48 pm

Re: processing multiple textfields with php

Post by njm »

Thank you Shawn.

1. I have something similar to that. I have my concatenated phone number in $_POST['phone'], which is a $_POST element I created, it's not a field on the form. When I submit the form and test for $_POST['phone'] above the DOCTYPE declaration it's empty, but when I test it near my 3 phone fields, it has a value. Do you know why that might be?

2. label for="State">State:</label>
<select name="State" id="State">
<option selected="selected">-Select One-</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AR">Arkansas</option>
<option value="AZ">Arizona</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
.....
</select>
Here, I'm trying to preserve the state that was selected if any invalid input is given and the form re-displays. This is easy to do with a text field or a checkbox, but here I don't know where to put the PHP to echo the selected state. Is something needed to 'remember' what state was selected? Any help would be very much appreciated.

Thank you again Shawn.

Nick
Post Reply