Friday, 15 May 2015

php - How to Access $_POST Data Across Multiple Forms -



php - How to Access $_POST Data Across Multiple Forms -

for shopping cart application i'm working on class, have display info across every step. problem can display info previous step. step 1, item selected radio box. stored so:

function processstep1() { //implemented sessions $_session["items"] = $_post["items"]; displaystep2(); }

step 2 asks quantity , validates it, so:

function processstep2() { //implemented sessions $_session["quantity"] = $_post["quantity"]; if ( preg_match('/^\d+$/',$_post["quantity"]) ) { displaystep3(); } else { echo "error: quantity entered invalid. please seek again."; displaystep1(); } }

(as aside, can't seem refresh current step (which displaystep2) when input not integer, error every time seek so. if has reply why is, additionally helpful.)

but on step 3 of form, seek run next line:

<p>you have selected <?php echo $_post["quantity"] ?> units of <?php echo $_post["items"] ?>.<p>

which responds error every time. have tried various configurations of same output, , have determined parse $_post["quantity"], never $_post["items"]. need both.

your 3rd form not "see" $_post['items'] because not submitted form. stored in session instead. start new session on 3rd form , request $_session['items'].

step 1

<form name="step1" method="post" action="whateverpagecontaintsprocessstep1.php"> <input type="radio" name="items" value="item1">item 1 <input type="radio" name="items" value="item2">item 2 </form>

when submit our form $_post info going send value of radio button selected selected.

step 2

<form name="step2" method="post" action="whateverpagecontaintsprocessstep2.php"> <input type="number" name="quantity" value="0" /> </form>

when submit form2 $_post info contain value of textbox called quantity, since form not contain previous radio buttons value not send server , therefor not able access in 'whateverpagecontaintsprocessstep2.php'.

php forms

No comments:

Post a Comment