views:

38

answers:

1

Here is my code in php. I have a php creditcard confirmation page, with 2 button, edit details and submit. I have an init file which will perform tasks based on what cc_confirm is and what editval is, confirm and editing details respectively.

if($_POST['cc_confirm1']=='y' && $_POST['$editval']!='y' && !isset($editval)) {echo '<input name="submitbtn" type="submit" value="Edit Details" /><input name="editval" type="hidden" value="y" /><input name="cc_confirm" type="hidden" value="n" />';
} if($_POST['cc_confirm1']=='y' && $_POST['$editval']!='y' && !isset($editval)){ echo '<input name="submitbtn1" type="submit" value="Submit Card" /><input name="card1" type="hidden" value="y" /><input name="cc_confirm" type="hidden" value="y" />';

Now the problem is, because I am using two hidden items, always the one at the bottom is being executed. For this code, if i press on edit details, the details are being submitted, the credit card is being runned and then edit page is shown after that, which does not serve the purpose.

If i interchange both button codes, then even for submit card, it is showing only edit page details without submitting card. I have tried to change the name of the buttons but no use.How can i avoid this problem? Appreciate any effort to solve.

A: 

Why don't you split up the conditions by assigning a value to them

$continue = 0;
if($_POST['cc_confirm1']=='y'){
$continue++;
}
if($_POST['$editval']!='y'){
$continue++;
}
else{
$continue = 0;
$reason = 'editval';
}
if(!isset($editval)) {
$continue++;
}
else{
$continue = 0;
$reason = 'noeditval';
}
if($continue > 0){
echo '<input name="submitbtn" type="submit" value="Edit Details" /><input name="editval" type="hidden" value="y" /><input name="cc_confirm" type="hidden" value="n" />';
} 
else{
    if($reason == 'editval'){
    //Process
    }
    elseif($reason == 'noeditval'){
    //Process
    }
}
Refiking
THanks for your reply. Your code, looks nice, but the problem is that, the conditions for both the buttons are the same. So $continue value will increase for sure. If there were any condition which is not same for both buttons then I would have not had any problem. Both these buttons need to be shown but the hidden values need to be specific to the button that is pressed... :(
Scorpion King