This topic is locked

Redirect to Another Page

8/11/2006 1:13:22 PM
PHPRunner General questions
paperhog author

I am just learning and having some problems, there is no working example to work of of which would help.

I am entering a record and then want to enter details about that record so I want to redirect to the next form so one field would already be filled out the (drop down) but it is not the redirect is fine but something here must be change to take the value of code with it

***

function BeforeAdd(&$values)

{
// Parameters:

// $values - Array object.

// Each field on the Add form represented as 'Field name'-'Field value' pair
//** Redirect to another page ****

header("Location: _price_history_add.php");

exit();

return true;
// return true if you like to proceed with adding new record

// return false in other case
}

___

No matter what I change I get an error.
Please help I have many multi step forms I want to use.
Thanks

Lori

rjks 8/12/2006

Hi Lori,
I was just reading through and saw your question, I am using the redirect to jump to the next required input of my data.
Objekt is the master and einheit is the child, I think you are in the wrong event, I use afteradd().

function AfterAdd()

{

//********** Redirect to another page ************
$i_id = mysql_insert_id();
$b_info = "Tabelle Objekte - Satz ID : ".$i_id." wurde erzeugt!";

write_log(2,"'".$_SESSION["UserID"]."'",$b_info,0,"System erzeugt");
$_SESSION["acc_einheit_masterkey"]=$i_id;

header("Location: acc_einheit_add.php");

exit();

}


Hope it helps.
Robert

J
Jane 8/15/2006

Lori,
use After record added event for your purpose.

paperhog author 8/23/2006

Ok this part worked - Thanks a BUNCH

global $conn;

$str = "select LAST_INSERT_ID() from printing_req";

$rs = db_query($str,$conn);

$data = db_fetch_numarray($rs);

header("Location: _print_req_details_add.php");

exit();


**how do I move on from Edit?

They may or may not have filled out page 2?

So I need to check if there is a record first if so pull it and got to edit if not go to the add page.
[code]global $conn;

$strSQLExists = "select from _print_req_details where print_id='print_id'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something
$str = "select
from _print_req_details where print_id='print_id'";

$rs = db_query($str,$conn);

$data = db_fetch_numarray($rs);
header("Location: _print_req_details_edit.php");

exit();
}

else

{

// if dont exist do something else
$str = "select LAST_INSERT_ID() from printing_req";

$rs = db_query($str,$conn);

$data = db_fetch_numarray($rs);

header("Location: _print_req_details_add.php");

exit();
I am getting to the right page but without the information I need (print_det_id: , print_id) I am just learning php some one please help, Ilearn from examples and their are not many ''REAL" examples to choose from.

J
Jane 8/24/2006

Lori,
what event you use?

paperhog author 8/27/2006

Lori,

what event you use?


After Record Updated.

J
Jane 8/28/2006

Lori,
try to check your code:

global $conn;

$strSQLExists = "select from _print_req_details where print_id='print_id'";

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

// if record exists do something
$str1 = "select
from _print_req_details where print_id='print_id'";

$rs1 = db_query($str1,$conn);

$data1 = db_fetch_numarray($rs1);

// to save field value use $_SESSION["value"] variable

$_SESSION["value1"] = $data1["FieldName"];

//


header("Location: _print_req_details_edit.php?editid=".$data["PrimeryField"]);

exit();
}

else

{

// if dont exist do something else
$str2 = "select LAST_INSERT_ID() from printing_req";

$rs2 = db_query($str2,$conn);

$data2 = db_fetch_numarray($rs2);

// to save field value use $_SESSION["value"] variable

$_SESSION["value2"] = $data2["FieldName"];

//


header("Location: _print_req_details_add.php");

exit();



Wrong places are in Italic.

Also you can save your values in the $_SESSION["value"] variable. And then use $_SESSION["value"] in the other events.

PrimeryField is your actual field name where primery key is stored.

spettinato 2/5/2007

***

function BeforeAdd(&$values)

{
// Parameters:

// $values - Array object.

// Each field on the Add form represented as 'Field name'-'Field value' pair


Can you tell me how can i represent my form field here using echo?

I'd like to show in echo the fields i'm using, that are:

id, name, email
Please help me. Tanx.

J
Jane 2/6/2007

Hi,
you can do it using the following code:

echo "id - ".$values["id"]."
";

echo "name - ".$values["name"]."
";

echo "email - ".$values["email"];



where id, name and emauk are your actual field names.

spettinato 2/6/2007

Hi,

you can do it using the following code:
where id, name and emauk are your actual field names.


But how can i know wich one are my actual field names?

'Cause i have 3 fields: id_questionario, data, name

But at the end of inserting, i don't know how to call them. Can you help me for this? Tanx a lot.

spettinato 2/6/2007

Ok i solved putting the code in "before record added" event. But now, i want to pass an id to another page. So i think i should insert something in "after record added" events. How can i? Tanx.

J
Jane 2/6/2007

To pass one of the field value to another page use $_SESSION variable.

Use following code on the Before record added event:

$_SESSION["FieldName"]= $values["FieldName"];



And then use $_SESSION["FieldName"] as default value for the field in the another table on the "Edit as" settings dialog on the Visual Editor tab.

spettinato 2/6/2007

I post my solution.
I put this in a page,

function AfterAdd()

{

//********** Redirect to another page ************
//********** Check if specific record exists ************

global $conn;
$_SESSION["id_questionario"]=mysql_insert_id($conn);

header("Location: weblearning_domande_add.php");

exit();

}


and this other code in the second page, called by the first, in the "on load event":

echo $_SESSION["id_questionario"];


And now it works. Tanx to all. I hope this can help someone else. Phprunner is a very good software. The best i tried to make php.