Link to home
Start Free TrialLog in
Avatar of lword
lword

asked on

how to retain a value (which is assigned from the url) while submitting the page(using php)

iam assigning two values say clientid and jobid from the url to the page.After all the details have entered and while saving the page the clientid and jobid becomes nothing.the problem is to retain the value when the page gets saved.
how to solve this ?
SOLUTION
Avatar of sajuks
sajuks

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lword
lword

ASKER

i have userd the post method for the page.
i will be submitting the page twice.(one is for the search and the other is for save).
while the search button is clicked, i will take the clientid and jobid from  the url link.And both the values are assigned.The url will not be there.After i enter the other details to the page and i will save all the details.In this case what happens,the hidden values are set to nothing.how to retain the value in this case and how to solve this?plz tell me its urgent!!!!



it seems that sajuks comment is correct.
However, if you need further help, the only way is to post you code here for EE perusal and possible correction and advice!
Avatar of lword

ASKER

i have give the code below:


<html>
<head>
<title></title>
<script language="JavaScript">
<!--
       
 function ValidateOnSubmit()
 {
      searchstring  = document.artinfo.searchval.value;
      LabelSearchString = "Search pattern";
      
      
      document.artinfo.searchval.value = searchstring;
      document.artinfo.hidefetch.value = 'Search';
      
      document.artinfo.changed.value = 2;  
      document.artinfo.ivalue.value = "";  
      document.artinfo.fvalue.value = "";  
      var commun_clientname=document.artinfo.hidclientname.value;
      var commun_jobtitle=document.artinfo.hidjobtitle.value;

      return true;
 }

 

 function sortby()  
 {
       document.artinfo.submit();
 }

 function SaveFunction()
 {
      RepBackSlash();
      LabelSummary ="Communication Summary";
      alert('%%%%%%');
      commsummary = document.artinfo.commsummary.value;
      subject=document.artinfo.subject.value;
      
      commun_jobid=document.artinfo.hidjobid.value;
      peopleid=document.artinfo.hidpeopleid.value;
      
      document.artinfo.submit();
      return true;
 }

 function CloseDiv()
 {
       document.all.divpeople.style.visibility='hidden';
 }


 function SelectPeople(peopleid)
 {
       searchstring=document.artinfo.hidefetch.value;
       document.artinfo.hidpeopleid.value=peopleid;
       document.artinfo.hidcontactperson.value= surname;
             
       document.artinfo.submit();
       return true;
 }
 -->
</script>
</head>

<?
print "<body bgcolor=$mailpagebgcolor topmargin=$bodytopmargin leftmargin=$bodyleftmargin onload='this.focus()'>";
?>

<form name ="artinfo" method ="post" action ="TelecommunCView.php">

<?

print "<tr bgcolor=$mailfeedbackbgcolor><td height=$mainfeedbacktdheight>";
print "<font color=$mainfeedbackfontcolor size=$mainfeedbackfontsize face=$mainfeedbackfontface>";

if($ret_accright ==1)
{
      print ("&nbsp;<image src=$mainfeedbackimage><b>&nbsp;$MsgAccessRights</b>");
      exit;
}
else if($ret_accright ==3 )
{
      print("&nbsp;<image src=$mainfeedbackimage><b>&nbsp;$MsgNotLoggedIn</b>");
      exit;
}

//query to display while the search button is submitted
if ($hidefetch == 'Search')
{
      $rs_query=pg_exec("select people.people_id,people.surname,people.user_id from people where upper(people.surname) like              upper('%$searchval%') order by upper(people.surname)");
    $nrows = pg_numrows($rs_query);
}

if(( $hidefetch == 'Search' and $nrows ==0))
{
      print ("<image src=$mainfeedbackimage>&nbsp;<b>No Match Found</b>");
}


 if($modeofcomm == "3")
 {
       print "<script>";
       print "var sourcepage ='TelecommunCView.php';";
       print "</script>";
 }
 
////////////////////HIDDEN VARIABLES DECLARATIONS///////////////////////
print "<input type=hidden name=hidclientname value='$commun_clientname'>";
print "<input type=hidden name=hidjobtitle value='$commun_jobtitle'>";

print "<input type=hidden name=hidefetch value='$hidefetch'>";

print "<input type=hidden name=hidclientid value='$commun_clientid'>";
print "<input type=hidden name=hidjobid value='$commun_jobid'>";

print "<input type=hidden name=divclose>";
print "<input type=hidden name=hidcontactperson value=$hidcontactperson>";
print "<input type=hidden name=hidpeopleid value=$hidpeopleid>";

/////////////////////HEADER///////////////////////////////////////////
print "<table width=100% border='0' align=$maintablealign cellpadding=$maintablecellpadding cellspacing=$maintablecellspacing>";
print "<tr bgcolor=$mailtitlebgcolor>";
print "<td id=feedback1 valign=top align=left nowrap colspan=3><font face=$reptabheadfontface size=$reptabheadfontsize>";
print "&nbsp;&nbsp;<b>Start TeleCommunication</b>";
print "</td>";
print "</tr>";
print "</table>";
print "<br>";

/////////////////CLIENT NAME//////////////////////////////////////
print "<table width=100% border=0 cellpadding=0 cellspacing=0 bordercolor=$reptabfieldbgcolor align=$reptabtopdisplayalign>";
print "<tr><td width=10% nowrap id=cid name=cid><font size=$reptabheadfontsize face=$reptabheadfontface>";


if ($hidclientname !='')
{
      print "&nbsp;&nbsp;&nbsp;Client Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: $hidclientname</td>";
}
else
{
            print "&nbsp;&nbsp;&nbsp;Client Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: $commun_clientname</td>";
}

print "<td>";
print "<font color=$othertextcolor size=$reptabheadfontsize face=$reptabheadfontface>";
print "</td></tr>";

/////////////////PROJECT NAME//////////////////////////////////
print "<tr><td width=10% nowrap id=jid name=jid><font size=$reptabheadfontsize face=$reptabheadfontface>";print "<br>";
if ($hidjobtitle !='')
{
      print "&nbsp;&nbsp;&nbsp;Project Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: $hidjobtitle</td>";
}
else
{      
      print "&nbsp;&nbsp;&nbsp;Project Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: $commun_jobtitle</td>";
}

print "<font color=$othertextcolor size=$reptabheadfontsize face=$reptabheadfontface>";
print "</tr></table>";

////////////////CONTACT PERSON///////////////////////////////
print "<table width=95% border='0' cellpadding=$maintablecellpadding cellspacing=$maintablecellspacing>";
print "<tr>";
print "<td width='25%' name=hidcontactperson align=left id='contperson'>";
print "<font face=$reptabfieldfontface size=$reptabfieldfontsize color=$reptabfieldfontcolor>";
print "&nbsp;&nbsp;&nbsp;Contact Person";
print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: $hidcontactperson";
print "<td width='14%' align=left id='SearchPeopleid'>";
print "<font face=$reptabfieldfontface size=$reptabfieldfontsize color=$reptabfieldfontcolor>";
print "<input type=text name='searchval' size=32>";
print "&nbsp;<input type='submit' value='Search' name='fetch' onclick='return ValidateOnSubmit()'>";
print "</font>";
print "</td></tr>";
print "<br>";

print "</tr></td>";
print "</table>";
//print "<br>";


//*******************************Div for listing all the peoplenames
//************************************************/

if ($hidefetch !='')
{
if($nrows<17) {$scrollheight2=18*$nrows;}
else{$scrollheight2=300;}

print "<div id='divpeople'
                     style ='position: absolute;
               width: 30%;
               height: $scrollheight2;
               visibility:visible;
               top:20%;
               left:60%;
               border:1;
                 z-index:111003;
                 background-color:$reptabheadbgcolor;
               border:1px outset;'>";
print "<table width=$reptabwidth border=0 cellpadding=$reptabcellpadding cellspacing=$reptabcellspacing align=$reptabalign bordercolor='$reptabbordercolor'>";
print "<td width=50%>";
//print "<tr bgcolor='$reptabheadbgcolor' id=$Peopleid>";
//print "<td width=30%>";
//print "<font face=$reptabfieldfontface size=$reptabfieldfontsize color=$reptabfieldfontcolor>";
//print "<a href=# title='Select all'>&#9668;</a>";
//print "<b>Select</b>";
//print "</td>";
print "<font face=$reptabfieldfontface size=$reptabfieldfontsize color=$reptabfieldfontcolor>&nbsp<b>People Name</b></font>";
print "<td width=50% align=right><a href=# onclick='CloseDiv()'><b><font size=3 style='background-color:$reptabfieldbgcolor' color='gray'>&nbsp;X&nbsp;</a></font></b></td>";

        if($nrows>0)
         {
               for($i=0;$i<$nrows;$i++)
               {
                    
                     $peopleid= pg_result($rs_query,$i,"people_id");
                     $surname= pg_result($rs_query,$i,"surname");
                     $user_id=pg_result($rs_query,$i,"user_id");
                     //print "<script language='javascript'>
                     //ArrPeopleNameLookUp[$peopleid][$nrows]=peopleid;
                     //ArrPeopleNameLookUp[$i]=$peopleid;
                     //ArrPeopleNameLookUp[$i][$peopleid]=$surname;
                     //</script>";
                     //print "ArrPeopleNameLookUp[$i][$surname] = $surname";
                     print "<tr bgcolor='$reptabheadbgcolor'>";
                     print "<td width=30% nowrap>";
                     print "<a title='Select the Contact Person' onclick='return SelectPeople($peopleid)'";
                     print " href='TelecommunCView.php?hidpeopleid=".urlencode($peopleid)."&hidcontactperson=".urlencode($surname)."&hidclientname=".urlencode($hidclientname)."&hidjobtitle=".urlencode($hidjobtitle)."&hidclientid=".urlencode($hidclientid)."&hidjobid=".urlencode($hidjobid)."'>";
                    
                     print "&nbsp;&#9668</a><font face=$reptabfieldfontface size=$reptabfieldfontsize color=$reptabfieldfontcolor>&nbsp;$surname</font></td></tr>";
                                                                                  
               }
           }
         print "</td>";
         print "</tr>";
         print "</table>";
         print "</DIV>";
       print "<br>";
}
else
{
      print "<div id='divpeople'
                          style ='position: absolute;
                  width: 30%;
                  height: $scrollheight2;
                  visibility:hidden;
                  top:20%;
                  left:60%;
                  border:1;
                    z-index:111003;
                    background-color:$reptabheadbgcolor;
                  border:1pz outset;'>";
      print "</div>";
}
print "<br>";
      
/********************************End of div*********************************************/

////////////////////FOR SUBJECT////////////////////////////
print "<table width=10% border='0' cellpadding=$maintablecellpadding cellspacing=$maintablecellspacing>";
print "<tr>";
print "<td width='45%' nowrap align=left id='subject'>";
print "<font face=$reptabfieldfontface size=$reptabfieldfontsize color=$reptabfieldfontcolor>";
print "&nbsp;&nbsp;&nbsp;Subject";
print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: ";
print "<td width='25%' align=left>";
print "&nbsp;<input type=text value='$subject' name='subject' size=58>";
print "</font></td></tr></table>";
print "<br>";

//////////////COMMUNICATION DETAILS//////////////////////
print "<table width=100% border='0' align=$maintablealign cellpadding=$maintablecellpadding cellspacing=$maintablecellspacing>";
print "<tr>";
print "<td width=23% align=left colspan='2'>";
print "<font face=$reptabfieldfontface size=$reptabfieldfontsize color=$reptabfieldfontcolor>";
print "&nbsp;&nbsp;&nbsp;Enter Communication Details&nbsp;<font size=$asteriskmarksize color=$mandasteriskmarkcolor>*</font>&nbsp;&nbsp;&nbsp;:<br>";
print "</br></td></tr></table>";
print "<tr>";
print "<td>";
if ($hidcontactperson !='')
{
print "&nbsp;&nbsp;<textarea name=commsummary rows=20 cols=90>";
}
else
{      
print "&nbsp;&nbsp;<textarea name=commsummary rows=20 cols=70>";
}
print "</textarea>";
print "<br>";
print "</td></tr>";

////////////////SAVE BUTTON/////////////////////////////
print "<table width='5%' border='0' align='center' cellpadding='0' cellspacing='0' bordercolor='maroon'>";
print "<td width='100%'align=center>";
print "<tr><br>&nbsp;&nbsp;";
                     
print "&nbsp;&nbsp;&nbsp;&nbsp;<input type=submit name=hidsave value='Save'
         style='border:1px solid maroon;background-color:$savebutcolor; '
         onmouseover='document.artinfo.hidsave.style.backgroundColor=\"$butovercolor\" ;document.artinfo.hidsave.style.color=\"white\"''
       onmouseout='document.artinfo.hidsave.style.backgroundColor=\"$savebutcolor\"; document.artinfo.hidsave.style.color=\"$delfontcolor\"'
       onClick='return SaveFunction();'>";

print "</td></tr></table>";

///newly added function to save the telecommuncations details
//function addTeleComm($hidclientid,$hidjobid,$hidpeopleid,$subject,$commsummary,$id)
//{
      
//}


print"@@@$hidclientid,$hidjobid";

///save validations
if($hidsave=='Save')
{
      if($id=='') {$id=0;}
      //if($hidclientid==''){$hidclientid=0;}
      //if($hidjobid==''){$hidjobid=0;}
      
      print"&&&$hidclientid,$hidjobid";
      $rs_result =pg_exec("select sp_addTeleComm('$hidclientid','$hidjobid','$hidpeopleid','$subject','$message','$id')");
      print "addTeleComm('$hidclientid','$hidjobid','$hidpeopleid','$subject','$commsummary','$id')";
      $ret = pg_result($rs_result,0,0);
      return $ret;
      /*$a = new add();
      print "addTeleComm($hidclientid,$hidjobid,$hidpeopleid,$subject,$commsummary,$id)";
      $ret_add = $a->addTeleComm('$hidclientid','$hidjobid','$hidpeopleid','$subject','$commsummary','$id');
      print "$ret_add";
      
      if($ret_add==0)
      {
            print "&nbsp;<image src=$mainfeedbackimage><b>&nbsp;TeleCommunication details were successfully saved</b>";
      }*/
}
?>
</form>
</body>
</html>
You need to keep forwaring the hidden values to the next pages.
for ex:
in ur first page from ur query sting you've assigned the two values to a hidden fiedld clientid and jobid.
now when you submit this page the on the second page you can refer to this value as
$hidden1 = $_POST[clientid];
$hidden2 = $_POST[jobid];
now if you are submitting this page agin then like in the first page you need to have the values of $hidden1 and $hidden2 carried forward .
it seems to me that the code is there to store keep the value of the hidden field once they are set.
* However, I'm not too sure if the a field is ever set properly

function SelectPeople(peopleid)
 {
      searchstring=document.artinfo.hidefetch.value;
      document.artinfo.hidpeopleid.value=peopleid;
      document.artinfo.hidcontactperson.value= surname;
           
      document.artinfo.submit();
      return true;
 }

I reckon the hidcontactperson is never set because surname is not set anywhere in this function

* I'm not too sure if this code is helping as well

////////////////CONTACT PERSON///////////////////////////////
print "<table width=95% border='0' cellpadding=$maintablecellpadding cellspacing=$maintablecellspacing>";
print "<tr>";
print "<td width='25%' name=hidcontactperson align=left id='contperson'>";

the td tag has a name identical to the name of your hidden field

* Also you set a number of javascript variable commun_.... and after you reuse them in php as $commun_...
In my mind, javascript is client side and php is server side, therefore this variable can not be used in the same context.

I'm concern that all these issues nneds to be addressed if you want to make sure that everything works as you expect!

Cheers,

Alain
Avatar of lword

ASKER

i have used $_POST but it does not retain the value.
is there any other any to solve the problem?
plz.......
sorry as i dont've php installed on this machine i cant be of much help.
Have a look at http://www.codehelp.co.uk/php/form.php#form
in the above example it shows how to read either from a querystring is present or the hidden value depending on what is set.
taht might be of use to you.
and @alain34 has raised some very good points..
Avatar of lword

ASKER

hai alain34,

This function sets the contactperson value and also all the values inside the selectpeople function.
while saving the savefunction is called and hidsave is set to save,after i print the clientid and jobid then the values are become nothing.
how to retain these values at this stage?
plz................

I understand your problem, however your code has prior issues to be solved.
first of all, you should change the selectPeople function to add the 'surname' argument.
you should change the td name with hidcontactperson.
Could you explain to all EE with some variable set in javascript are expected to be used in php?
send those two values to sessions variables to be retrieved at a later time