1

How would I go about parsing incoming form data where the name changes based on section of site like:

<input type="radio" name="Motorola section" value="Ask a question">

where 'Motorola section may be that, or Verizon section, or Blackberry section, etc.

I do not have any control over changing the existing forms unfortunately, so must find a way to work with what is there.

Basically, I need to be able to grab both the name="" data as well as its coresponding value="" data to be able to populate the email that gets sent properly.

3 Answers 3

2

Well, you don't receive a HTML form, but just field names and values in $_POST. So you have to look what to make out of that.

Get the known and fixed fields from $_POST and unset() those you've got [to simplify]. Then iterate over the rest. If " section" is the only constant, then watch out for that:

foreach ($_POST as $key=>$value) {
    if (stristr($key, "section")) {
        $section = $value;
        $section_name = $key;
    }
}

If there are multiple sections (you didn't say), then build an section=>value array instead.

Sign up to request clarification or add additional context in comments.

Comments

0
<form action="formpage.php" method="post">
<input type="radio" name="Motorola_section" value="Ask a question">


</form>
$motorola = $_POST['Motorola_section'];
if ($motorola =='Ask a question')
{
form submit code if motorola is selected
}

Comments

0

Well, first off, you shouldn't have spaces in the name field (even though it should work with them).

Assuming it's a form, you can get the value through the $_POST (for the POST method) and $_GET (for the GET method) variables.

<?php
if ( isset( $_POST['Motorola section'] ) ) // checks if it's set
{
   $motoSec = $_POST['Motorola section'];  // grab the variable
   echo $motoSec; // display it
}
?>

You can also check the variables using print_r( $_GET ) or print_r( $_POST ).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.