0

I know it is something simple but not sure why my php form is returning just the word "Array". Here is the part of the form and the php for the "review" page that is retuning the "Array".

form.php

<div class="clubPhotos">
    <div class="club">
        <img src="clubs/img/praxispi.png" class="clubPhoto" />
        <span class="clubTitle">Praxis PI</span>
        <span class="clubSub">Low Launch 9.5</span>
        <input type="checkbox" id="clubCheckbox4" class="clubCheckbox" name="DriverType[Low Launch 9.5]" value="Praxis PI Low Launch 9.5" />
    </div>
    <div class="club">
        <img src="clubs/img/praxispi.png" class="clubPhoto" />
        <span class="clubTitle">Praxis PI</span>
        <span class="clubSub">Mid-Low Launch 12.5</span>
        <input type="checkbox" id="clubCheckbox1" class="clubCheckbox" name="DriverType[Mid-Low Launch 12.5]" value="Praxis PI Mid-Low Launch 12.5" />
    </div>
    <div class="club">
        <img src="clubs/img/praxispi.png" class="clubPhoto" />
        <span class="clubTitle">Praxis PI</span>
        <span class="clubSub">Mid-High Launch 15.5</span>
        <input type="checkbox" id="clubCheckbox2" class="clubCheckbox" name="DriverType[Mid-High Launch 15.5]" value="Praxis PI Mid-High Launch 15.5" />
    </div>
    <div class="club last">
        <img src="clubs/img/praxispi.png" class="clubPhoto" />
        <span class="clubTitle">Praxis PI</span>
        <span class="clubSub">High Launch 18.5</span>
        <input type="checkbox" id="clubSelect" class="clubCheckbox" name="DriverType[High Launch 18.5]" value="Praxis PI High Launch 18.5" />
    </div>
    <div class="clear"></div>
</div>

review.php

echo (!empty($_REQUEST['DriverType'])) ? "<div class='reviewItem'><span class='reviewTitle'>Driver:</span>{$_REQUEST['DriverType']}</div>" : "";

I tried changing the to DriverType[] but no success.

2
  • You can't echo an array. Try print_r($_REQUEST['DriverType']) to see the structure and values of your array. Then you could loop through it. Commented Dec 13, 2013 at 19:09
  • Rule 1: You don't echo arrays. Use a loop, or echo only the specific index you need. (hint: print_r($_REQUEST['DriverType']); will list the array contents for you) Commented Dec 13, 2013 at 19:10

2 Answers 2

5

$_REQUEST['DriverType'] is an array. Therefore the values you want are found in an array within it. You will need to loop through the array to get the values from it.

I suspect you only want one item so changing these to radio buttons might be a batter way to go:

<input type="radio" id="clubSelect" class="clubCheckbox" name="DriverType" value="Praxis PI High Launch 18.5" />

Then your code will work as expected.

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

2 Comments

Good suggestion to use radio buttons - that guarantees there will be just one choice. I was just looking over the code to search for that information when you edited your answer...
Yeah, it didn't occur to me at first but then it once I understood what they really wanted it seemed like the best solution.
2

Try

echo $_REQUEST['DriverType'][0]

I suspect you are only interested in one element.

1 Comment

Except their array looks like this: $_REQUEST['DriverType']['High Launch 18.5']

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.