Jump to content

Passing an array variable from a questionnaire to another page.


sdyates2001

Recommended Posts

I seek your wisdom and direction. I am an experienced perl programmer and am assisting a friend with some php code. While I am good with perl and know the resources to use when in need, I can't say that with php.

 

I am looking to create a simple questionnaire that consists of about 15 questions resulting in a yes or a no. Based on the response, I will forward this array to another page, perform a simple if then logic that will see one of three html pages display.

 

While I have Programming PHP, I am having trouble as this book is not tailoured to what I need to do.

 

As I don't believe if having others do my code for me, I am good at reverse engineering code for my own needs.

 

Could someone please provide me some sample code similar to what I am asking or a good tutorial page for what I need.

 

Thanks Kindly,

Link to comment
Share on other sites

Don't worry that's simple.  ;D

 

When you submit an html form, they are stored in  a php array called $_POST

 

for example if you submit the following value

 

<input name="question1" value="yes" />

 

then in php you can get the value will be stored here:

 

$_POST['question1']

Link to comment
Share on other sites

I'm assuming your questionnaire is a form. So by clicking the submit button you automaticly input all values into an array called

 

$_POST['value']

 

If your form method reads:

 

method="post"

 

on the page specified in the

 

action="anwser.php"

 

The following is a site I made that asks 'do you like sports' and you anwser yes or no. When you hit 'submit' it sends you to another website specified in action="" the page it sends you to automaticly has all the information with-in $_POST[''].

 

// Input page
<form id="form1" name="form1" method="post" action="anwser.php">//page info will be sent to
  Do you like sports?
  <table width="200">
    <tr>
      <td><label>
        <input type="radio" name="sports" value="Yes" />
        Yes</label></td>
    </tr>
    <tr>
      <td><label>
        <input type="radio" name="sports" value="No" />
        No</label></td>
    </tr>
  </table>
  <label></label>
  <label>Submit
  <input type="submit" name="submit" value="Submit" />
  </label>
</form>

 

So say I want to call their input from the last page I simply have to type.

 

//2nd Page that recieves the info from first page
<?php
$anwser = $_POST['sports'];
//the var $anwser now contains the anwser either Yes/No based on what they gave last page
echo $anwser;
//will post the anwser on the website
?>

 

I hope this helps, and there should be no need to make an array with their anwsers in it if you will call

$_POST[];

Link to comment
Share on other sites

@rubing

 

Thanks. I have been working for sometime... my perl is getting int he way.

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Questionnaire :: Sheri.com</title>

<form id="form1" name="form1" method="post" action="bob.php">
  <table width="200">
    <tr><td><font face='Arial' size='2'>Question 1</td>
<td><input type='checkbox' name='sports' value='$ARRAY[0]'>
    </tr>    
    <tr><td><font face='Arial' size='2'>Question 2</td>
<td><input type='checkbox' name='sports' value='$ARRAY[1]'>
    </tr>    
    <tr><td><font face='Arial' size='2'>Question 3</td>
<td><input type='checkbox' name='sports' value='$ARRAY[2]'>
    </tr>    
    <tr><td><font face='Arial' size='2'>Question 4</td>
<td><input type='checkbox' name='sports' value='$ARRAY[3]'>
    </tr>    
  </table>
  <label></label>
  <label>Submit
  <input type="submit" name="submit" value="Submit" />
  </label>
</form>

 

I need check boxes because I need to return the value for each check box. I need to know which ones were checked and which ones were not. When I display, I am not getting an array back. I am just getting $ARRAY[3] or another value, but not what it is...

 

<?php
$anwser = $_POST['sports'];
echo $anwser;
?>

 

I know this is simple, but I can't seem to bridge the perl gap ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.