1

I am creating a form input which the minimum amount for submitting is 700. Any values more than 700 should be taken as extra savings. It should save 700 as amount and the excess as extra saving. The form is working fine for values greater than 700 showing that my code works but it does not submit for input that is exactly 700.

   $extra_savings = 0;


   if ($amount_saved > 700) {
        $extra_savings = $amount_saved - 700;
        $amount_saved = 700;
    }

    // validate input
    $valid = true;
    if (empty($amount_saved)):
        $amount_savedError = 'Please enter amount saved';
        $valid = false;
    elseif ($amount_saved < 700):
            $amount_savedError = 'Amount Saved Should be 700 or more';
            $valid = false; 
    else:
        $valid = true;
    endif;  

Where is the problem?

4
  • 1
    if ($amount_saved > 700) { says lmore than 700, but 700 is allowed. So >= is wat you need Commented Jun 30, 2017 at 8:45
  • 1
    btw: See that you can put that value 700 in a constant: next year some one wants to change it to 750 and you have to check all your scripts to replace the value Commented Jun 30, 2017 at 8:46
  • Good point on the constant. Is there any problem on the validation conditions? I think that's why the validation is not passing. Commented Jun 30, 2017 at 9:07
  • The problem was on another validation Commented Jun 30, 2017 at 9:22

1 Answer 1

5

You have to use greater than or eqaul to , use this

$extra_savings = 0;


   if ($amount_saved >= 700) {
        $extra_savings = $amount_saved - 700;
        $amount_saved = 700;
    }

    // validate input
    $valid = true;
    if (empty($amount_saved)):
        $amount_savedError = 'Please enter amount saved';
        $valid = false;
    elseif ($amount_saved < 700):
            $amount_savedError = 'Amount Saved Should be 700 or more';
            $valid = false; 
    else:
        $valid = true;
    endif;  
Sign up to request clarification or add additional context in comments.

2 Comments

I was talking about the validation. Something is making the validation false when user inputs 700
I had an amount saved validation below that. That is where the problem was.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.