This topic is locked

Redirect to list after using Before add event

12/29/2016 3:44:30 AM
PHPRunner General questions
P
pamgeo author

Hi to all ,
I have a field that I have used to store multiple values and used the following example to create diferent records after I hit the add button
https://xlinesoft.com/phprunner/docs/select_multiple_values.htm
but then it returns an error where the error is the list page I am trying to redirect!
my code is as follows
if ($values['propertyid']) {
$arr = explode(",",$values["propertyid"]);
for ($i=0;$i<count($arr);$i++)
{

$strInsert = "insert into proprequest(status,origin,introfrom,code,custid,propertytype,propcategory,requestreason,dateuntilrequest,requesttimeframe,paymentterms,pricefrom,priceto,sizefrom,sizeto,bedroomsfrom,bedrommsto,floorfrom,floorto,constructfrom,constructto,transtype,branchid,propertyid)";

$strInsert.= "values (".$status.",".$origin.",".$introfrom.",(select getnewreqcode()),".$custid.",".$propertytype.",".$propcategory.",".$requestreason.",".$dateuntilrequest.",".$requesttimeframe;

$strInsert.= ",".$paymentterms.",".$pricefrom.",".$priceto.",".$sizefrom.",".$sizeto.",".$bedroomsfrom.",".$bedrommsto.",".$floorfrom.",".$floorto.",".$constructfrom.",".$constructto.",".$transtype.",(select branchid from property where id = ".$arr[$i]."),".$arr[$i].")";
db_exec($strInsert,$conn);
$newid = mysqli_insert_id($conn);
$strInsertArea = "insert into reqarea (reqid,areaid,userid,dateadded,active) ";

$strInsertArea .= "values (".$newid.",ifnull((select nareaid from areas a , property p where p.id = ".$arr[$i]." and a.nLevel3Code = p.district),(select nareaid from areas a , property p where p.id = ".$arr[$i]." and a.nLevel2Code = p.city and a.nLevel2descr is not null and nLevel3descr is null))";

$strInsertArea .= ",".$_SESSION["uid"].",now(),1)";

db_exec($strInsertArea);

}
// Exit and Redirect to the list page after updating database
header("Location: proprequest_list.php?a=return");

exit();
}
else {

$values['code']=DBLookup("select getnewreqcode()");

return true;
}
The insert is done correct , but the redirect fails as shown below


admin 12/30/2016

Redirect needs to be done in AfterAdd event, otherwise record won't be added. Also redirect in this event will only work on the regular Add page. It won't work with Add page in popup or in inline mode.

P
pamgeo author 12/30/2016



Redirect needs to be done in AfterAdd event, otherwise record won't be added. Also redirect in this event will only work on the regular Add page. It won't work with Add page in popup or in inline mode.


Hi Admin ,
Based on the example given on the manual the redirect is done in the before add event , this is because the records are added by the script to ensure that there will be as many records as the values selected in the multiselect field.
If I do this on the after add event then I will have 1 record with all the multiselected values on the field and then X(as many I have selected) records with the individual value.
Also the add page is the regular , not popup , not inline ...
I am following 100% the example given on the manual!