Okay, I am a serious newbie so I apologize if I use the wrong terminology. I originally created a forum in order to collect people's cell phone numbers. Now, I want to add a drop-down menu so I know which group they are in and if they do not select a group I want them to be prompted to. When I created the form originally I did it with someone else and they were a very savvy web designer, so they knew PHP. I am not as good. I know, a little about PHP, but not a lot. So I am not sure what to add to the post.php page.

I really could use some serious help. If someone would be so kind to help me I would surely appreciated.

So here is the form I created:

          <form action="post.php" method="post" >

         Phone number: <input name="phone_number" type="text" size="13" />
 Group:        
 <label>
           <select name="organization" size="1" id="organization">
             <option value="novalue" selected>Please choose one</option>
             <option value="stmichael">St. Michael's</option>
             <option value="stpeter">St. Peter's</option>
             <option value="stpierre">St. Pierre</option>
           </select>
         </label>
<input type="submit" name="send" value="Send" /><br /> 
                    <font size="2">(Do Not Include Dashes)</font>
        <br />
                <span id="sprycheckbox1">
                <label>
                      <input type="checkbox" name="agre" id="agre" />
                   <font size="2"> By selecting this box, I agree to <a href="#" onClick="MM_openBrWindow('terms_and_conditions_pop_up.html','','width=400,height=600')">terms and conditions</a></font></label>
                    <span class="checkboxRequiredMsg">Please select box.</span></span>
          </form>

Here is the post.php page:

<?php
if ($_POST['send'])
{
    // The HTTP class
    include_once('class.HttpClient.php');

    // The XML class
    include_once('class.xml_tree.php');

    // The configuration file
    include_once('config.php');

    $send['username'] = USERNAME;
    $send['password'] = PASSWORD;
    $send['trigger_id'] = TRIGGER_ID;

    // This is the phone number that you whant to send the campiang to
    $send["phone_number"] = $_POST['phone_number'];

    $send["phone_number"] = str_replace('-', '', $send["phone_number"]);
    $send["phone_number"] = str_replace('_', '', $send["phone_number"]);
    $send["phone_number"] = str_replace(' ', '', $send["phone_number"]);
    $send["phone_number"] = str_replace('.', '', $send["phone_number"]);

    if (strlen($send["phone_number"]) != 12 && strlen($send["phone_number"]) != 10)
    {
        $error_message = 'Invalid phone number, wrong len';
    }

    if (!is_numeric($send["phone_number"]))
    {
        $error_message = 'Invalid phone number, not numeric';
    }

    if (!$error_message)
    {
        $pageContents = HttpClient::quickPost("http://platform.3cinteractive.com/web_registration.php", $send);

        $xml_tree = new xml_tree($pageContents);

        if ($xml_tree->getPath("successNotification/message"))
        {
            header("Location: template_success.php");
            exit;
        }
        elseif ($error_message = $xml_tree->getPath("errorNotification/message"))
        {

            header("Location: template_error.php?error=".urlencode($error_message->content));
            exit;
        }
        else
        {
            header("Location: template_error.php?error=".urlencode("Unknow error"));
            exit;
        }
    }
    else
    {
        header("Location: template_error.php?error=".urlencode($error_message));
        exit;
    }
}
else
{
    header("Location: index.html");
    exit;
}

If I am understanding it right, you have two questions:
-How to make sure the user has selected an option?
-How to process that selection in your post.php file?

For the first question, you have two options:
1. Validating that an option has been selected from your list with JavaScript before the form is allowed to be submitted.
2. Using your post.php file to check whether a value was selected from the list after the form has been submitted.

I would suggest the first option, as it is easier to tell a user when they click "submit" that they forgot to select something from the list than to have PHP process the form, realize the mistake, and send the user back to the original page to do it all over again (and have an error message tell them what they did wrong).

Once you figure that out, you simply need to have post.php collect the information the same way it collects the rest of the form data. I'm not exactly sure how you're storing this information (ie are you sending it to a database?), but it will be the same process as with the rest of the form data.

Try figuring out how you want to validate the form with JavaScript before you worry about having to process the new field you're using. If you need extra help doing this or have any other questions, post back here and I'll try to help you out.

Good luck,
Ty

Thank you so much for your help. I was over complicating things. I took your advice and have the form validate your selection before submitting the form.
What scares me is the post.php page. What I know about PHP can fit into a thimble. The information is going to be sent to a database so what do I need to add to the page to make sure the phone number and group gets sent to the database together? Or do I not need to add any thing?
Here is the new code for the form.

     <form action="post.php" method="post" >

     Phone number: <input name="phone_number" type="text" size="13" />
 Group:        
 <span id="spryselect1">
 <label>
   <select name="organization" size="1" id="organization">
     <option selected>Please choose one</option>
     <option value="stmichaels">St. Michael's</option>
   </select>
 </label>
 <span class="selectRequiredMsg">Please select an item.</span></span>
<input type="submit" name="send" value="Send" /><br /> 
                    <font size="2">(Do Not Include Dashes)</font>
        <br />
                <span id="sprycheckbox1">
                <label>
                      <input type="checkbox" name="agre" id="agre" />
                   <font size="2"> By selecting this box, I agree to <a href="#" onClick="MM_openBrWindow('terms_and_conditions_pop_up.html','','width=400,height=600')">terms and conditions</a></font></label>
                    <span class="checkboxRequiredMsg">Please select box.</span></span>
          </form>
And here is the code for the post.php page:
<?php
if ($_POST['send'])
{
    // The HTTP class
    include_once('class.HttpClient.php');

    // The XML class
    include_once('class.xml_tree.php');

    // The configuration file
    include_once('config.php');

    $send['username'] = USERNAME;
    $send['password'] = PASSWORD;
    $send['trigger_id'] = TRIGGER_ID;

    // This is the phone number that you whant to send the campiang to
    $send["phone_number"] = $_POST['phone_number'];

    $send["phone_number"] = str_replace('-', '', $send["phone_number"]);
    $send["phone_number"] = str_replace('_', '', $send["phone_number"]);
    $send["phone_number"] = str_replace(' ', '', $send["phone_number"]);
    $send["phone_number"] = str_replace('.', '', $send["phone_number"]);

    if (strlen($send["phone_number"]) != 12 && strlen($send["phone_number"]) != 10)
    {
        $error_message = 'Invalid phone number, wrong len';
    }

    if (!is_numeric($send["phone_number"]))
    {
        $error_message = 'Invalid phone number, not numeric';
    }

    if (!$error_message)
    {
        $pageContents = HttpClient::quickPost("http://platform.3cinteractive.com/web_registration.php", $send);

        $xml_tree = new xml_tree($pageContents);

        if ($xml_tree->getPath("successNotification/message"))
        {
            header("Location: template_success.php");
            exit;
        }
        elseif ($error_message = $xml_tree->getPath("errorNotification/message"))
        {

            header("Location: template_error.php?error=".urlencode($error_message->content));
            exit;
        }
        else
        {
            header("Location: template_error.php?error=".urlencode("Unknow error"));
            exit;
        }
    }
    else
    {
        header("Location: template_error.php?error=".urlencode($error_message));
        exit;
    }
}
else
{
    header("Location: index.html");
    exit;
}

I haven't tested this, but I believe it would if you added the red line to this section of post.php:

$send = USERNAME;
$send = PASSWORD;
$send = TRIGGER_ID;
$send = ORGANIZATION;

This is assuming your database is able to handle the addition of another field, but I'm not sure what type of setup you're using to put this into the db.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.