Page 1 of 1

Help with array and form value

Posted: Sun Jan 04, 2009 4:57 pm
by jk2008
I need to separate the form in the following code into its own file but still have the function of the arrays working. I am new to php and have no clue how to achieve that. Can someone please take a look at the code point me to the right direction to accomplish it? I am just trying to have the form as its on file for easier modification if posibble.

Thanks.

Code: Select all

<?php
 
session_start();
 
// tell us which page this us, defined by the array just below
$pagenum = $_GET['refpage'];
 
// set your page title here
$pagetitle[1] = 'Page 1';
$pagetitle[2] = 'Page 2';
$pagetitle[3] = 'Page 3';
$pagetitle[4] = 'Page 4';
$pagetitle[5] = 'Page 5';
 
 
// defined the page urls to refer
$referurl[1] = 'page1.html';
$referurl[2] = 'page2.html';
$referurl[3] = 'page3.html';
$referurl[4] = 'page4.html';
$referurl[5] = 'page5.html';
 
 
$thisurl = 'http://'.$_SERVER['HTTP_HOST'].ltrim($_SERVER['PHP_SELF'], '/');
$refurl = 'http://'.$_SERVER['HTTP_HOST'].'/'.$referurl[$pagenum];
 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
 
<style type="text/css">
<!--
.fieldlabel {
    width: 150px;
    vertical-align: top;
    }
 
.fieldinput {
    width: 200px;
    text-align: right;
    vertical-align: top;
    }
 
h1 {
    font-size: 3em;
    color: #FFCC00;
}
 
#container { 
    width: 50%;
    margin: 0 auto;
    text-align: left;
}
 
.footer {
    background-color: #000;
    padding: 0.5em;
}
 
.leightbox {
    color: #333;
    display: none;
    position: absolute;
    top: 25%;
    left: 25%;
    width: 50%;
    height: 50%;
    padding: 1em;
    border: 1em solid #B8B8B8;
    background-color: white;
    text-align: left;
    z-index:1001;
    overflow: auto; 
}
 
#overlay{
    display:none;
    position:absolute;
    top:0;
    left:0;
    width:100%;
    height:100%;
    z-index:1000;
    background-color:#333;
    -moz-opacity: 0.8;
    opacity:.80;
    filter: alpha(opacity=80);
}
 
.lightbox[id]{ /* IE6 and below Can't See This */    position:fixed;    }#overlay[id]{ /* IE6 and below Can't See This */    position:fixed;    }
-->
</style>
<script type="text/javascript" src="scripts/prototype.js"></script>
<script type="text/javascript" src="scripts/lightbox.js"></script>
</head>
<body>
<!-- BEGING CODE FOR REFER -->
              <a href="#" rel="lightbox1" title="Refer <?=$pagetitle[1]?> to a friend!" class="lbOn">Refer <?=$pagetitle[1]?> to a friend!</a><br />
<a href="#" rel="lightbox2" title="Refer <?=$pagetitle[2]?> to a friend!" class="lbOn">Refer <?=$pagetitle[2]?> to a friend!</a><br />
<a href="#" rel="lightbox3" title="Refer <?=$pagetitle[3]?> to a friend!" class="lbOn">Refer <?=$pagetitle[3]?> to a friend!</a><br />
<a href="#" rel="lightbox4" title="Refer <?=$pagetitle[4]?> to a friend!" class="lbOn">Refer <?=$pagetitle[4]?> to a friend!</a><br />
<a href="#" rel="lightbox5" title="Refer <?=$pagetitle[5]?> to a friend!" class="lbOn">Refer <?=$pagetitle[5]?> to a friend!</a><br />
<?php
for($i=1;$i<=5;$i++)
{
?>
<div id="lightbox<?=$i?>" class="leightbox">
<form name="refer" id="refer" action="referproc.php" method="post" onsubmit="return validateOnSubmit()">
    <fieldset id="refertofriend" style="width: auto;">
    <legend>Refer <?=$pagetitle[$i]?> to a friend!</legend>
    <table border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td class="fieldlabel">Friend's name</td>
            <td class="fieldinput"><input name="friendsname" type="text" value="" />
            <br /><div id="errorfname"> </div></td>
        </tr>
        <tr>
            <td class="fieldlabel">Friend's email</td>
            <td class="fieldinput"><input name="friendsemail" type="text" value="" />
            <br /><div id="errorfemail"> </div></td>
        </tr>
        <tr>
            <td class="fieldlabel">Your name</td>
            <td class="fieldinput"><input name="yourname" type="text" value="" />
            <br /><div id="erroryname"> </div></td>
        </tr>
        <tr>
            <td class="fieldlabel">Your email</td>
            <td class="fieldinput"><input name="youremail" type="text" value="" />
            <br /><div id="erroryemail"> </div></td>
        </tr>
        <tr>
            <td class="fieldlabel">Message</td>
            <td class="fieldinput"><textarea name="message" cols="30" rows="6" ></textarea>
            <br /><div id="errormsg"> </div><br /></td>
        </tr>
        <tr>
            <td class="fieldlabel">Copy to self?</td>
            <td class="fieldinput"><input name="copy" type="checkbox" value="1" />
            <br /><div id="erroryemail"> </div></td>
        </tr>
        <tr>
            <td colspan="2" align="center"><br /><input type="submit" name="submit" value="submit" /></td>
        </tr>
    </table>
    </fieldset>
    <input type="hidden" name="pagename" value="<?=$pagetitle[$i]?>" />
    <input type="hidden" name="refurl" value="<?php echo 'http://',$_SERVER['HTTP_HOST'],'/',$referurl[$i]; ?>" />
</form>
    <p class="footer">
        <a href="#" class="lbAction" rel="deactivate">Close</a>
    </p>
</div>
<!-- END ERREFER CODE -->
       <?php
       } // end for statment
       ?></body>
</html>

Re: Help with array and form value

Posted: Sun Jan 04, 2009 5:42 pm
by it2051229
I had problems with this once where I wanted to pass an ARRAY to another page. I ended up storing my array values on a COOKIE or a SESSION which can then be used by the other page. The other way I did was to use the "include" like

referers.php

Code: Select all

 
<?php
$pagetitle[1] = 'Page 1';
$pagetitle[2] = 'Page 2';
$pagetitle[3] = 'Page 3';
$pagetitle[4] = 'Page 4';
$pagetitle[5] = 'Page 5';
  
// defined the page urls to refer
$referurl[1] = 'page1.html';
$referurl[2] = 'page2.html';
$referurl[3] = 'page3.html';
$referurl[4] = 'page4.html';
$referurl[5] = 'page5.html';
?>
 
phpfile1.php

Code: Select all

 
include("referers.php");
 
echo $referurl[1];
 
phpfile2.php

Code: Select all

 
include("referers.php");
 
echo $referurl[2];
 

Re: Help with array and form value

Posted: Wed Jan 07, 2009 1:43 am
by jk2008
Can you show me how to store on session and pass it to the form thru the link? I know how to pass the session value from a page to another but when I have an array/multiple value how do I pass only one value at a time to the same form?

how do I make sure Page 1 of $pagetitle[1] = 'Page 1'; and page1.php of $referurl[1] = 'page1.php' will be posted as hidden field in the form and thru link 1, Page 2 and page2.php will be pass to the form thru link 2 and so on.

The goal is to use the same form for all links but each link will give different value from the array to the form. I prefer not to put the variable and value on the link such as http://www.sample.com?variable=value.
it2051229 wrote:I had problems with this once where I wanted to pass an ARRAY to another page. I ended up storing my array values on a COOKIE or a SESSION which can then be used by the other page.

Re: Help with array and form value

Posted: Wed Jan 07, 2009 2:01 am
by omniuni
Tizag does a better job than I could explaining it:

http://www.tizag.com/phpT/phpsessions.php

Re: Help with array and form value

Posted: Wed Jan 07, 2009 4:00 am
by it2051229
Tizag does a better job than I could explaining it:
Yup, read it, you could either make use of 5 session variables(one session variable is possible for the 5 values but you're going to do splitting of values) for each values or you can wait for someone who has a better idea.

Oh and you can't pass sessions via post or get method(url). If you created a session from another page, that created session is automatically accessible by other pages provided that you know the session's name.