php if empty

marcinwolejko 20 Mar, 2015
Hi guys.
It's been a while since I asked for help.
I'm struggling with a short piece of code for my form.
I have a field with price which can be either calculated by a php script of filled in by hand by a user.
Now I want to write a condition that would check whether a user manually filled in the price and then leave it as it is or if the form field 'price' is empty run a php script.

I already have managed to write this piece of code but to my despair it does not work.
Can you help me out debuggin it?

<?php
if (!empty($form->data['price'])) {
$form->data['price'] = $form->data['onevalue'] * $form->data['secondvalue'] + 10;
}
else $from->dara['price];
?>


Thanks in advance!

Marcin
GreyHead 20 Mar, 2015
Answer
1 Likes
Hi Marcin,

Please try
<?php
if ( empty($form->data['price']) ) {
  $form->data['price'] = ( $form->data['onevalue'] * $form->data['secondvalue'] ) + 10;
}
?>

Bob
marcinwolejko 20 Mar, 2015
Bob,
You are the BEST!

Thank you🙂
This topic is locked and no more replies can be posted.