SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Need help with Array and Form

    For whatever reason, I am a real WIMP when it comes to Arrays...

    So anyways...

    I have a Form with 10 questions on it, and want to store each "Answer" in the $answerArray

    The Questions (and User's Answers) on my Form look like this...
    HTML Code:
    	<!-- Question 1 -->
    	<label for="question1">1.) Why did you decide to start your own business?</label>
    	<textarea id="question1" name="answerArray[0]" cols="60" rows="8"><?php if (isset($answerArray[0])){echo htmlentities($answerArray[0], ENT_QUOTES);} ?></textarea>
    	<?php
    		if (!empty($errors['question1'])){
    			echo '<br /><span class="error">' . $errors['question1'] . '</span>';
    		}
    	?>
    	<br />
    
    	<!-- Question 2 -->
    	<label for="question2">2.) What advice would you share with others on what NOT to do?</label>
    	<textarea id="question2" name="answerArray[1]" cols="60" rows="8"><?php if (isset($answerArray[1])){echo htmlentities($answerArray[1], ENT_QUOTES);} ?></textarea>
    	<?php
    		if (!empty($errors['question2'])){
    			echo '<span class="error">' . $errors['question2'] . '</span>';
    		}
    	?>
    	<br />

    Assuming my Form is okay, how do I store all of the Responses into an Array in the $_POST array?


    When my Form is submitted, I need a way to loop through each Answer and take the according action...

    Thanks,


    Debbie

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    When the form is submitted. PHP already builds an array for you.

    They're stored in $_POST['answerArray'][0], $_POST['answerArray'][1], etc.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •