Bobby
asked on
PHP nested IF statement... maybe something else would be better?
I need to add into the code below an IF statement (in the commented area), checking that the order number and a few other things are greater than 0... if they aren't, I need to return a message to the browser saying "no good" or whatever. If they are, then the code keeps going. The code below is tested and it worked, but now I just need that break in the middle that checks for data validation before inserting into the db and sending the email.
public function indexAction()
{
$request_result = array('success' => false);
if($this->get('security.context')->isGranted('ROLE_USER')) {
$em = $this->getDoctrine()->getEntityManager();
$dbAzure = new DbAzure();
$user = $this->container->get('security.context')->getToken()->getUser();
$request = $this->getRequest();
$om_customer_id = $user->getCustomer()->getOmCustomerId();
$order_number = $request->get('order_number');
$qm_sku = intval($request->get('qm_sku'));
$options = $request->get('options');
$qty = intval($request->get('qty'));
$email = $request->get('email');
// Verify data is correct.. order_number > 0....om_customer_id > 0.. qm_sku > 0... qty > 0
// if not value... don't write the info and return an error
$request_result['success'] = $dbAzure->submitReturnRequest($order_number, $qm_sku, $options, $qty);
$fullname = $user->getFirstName()." ".$user->getLastName();
$subject = "Return Request for OM Order Number ".$order_number."";
$message = \Swift_Message::newInstance()
->setSubject($subject)
->setFrom(array($email => $fullname))
->setTo(array("me@me.com"))
->setContentType( 'text/html' )
->setBody(
$this->renderView(
'MyAccountBundle:ReturnRequest:emailRequestProductReturn.html.twig',
array('fullname' => $fullname,
'om_customer_id' => $om_customer_id,
'qm_sku' => $qm_sku,
'email' => $email)
)
);
$this->get('mailer')->send($message);
}
$code = ($request_result['success'])?200:500;
return new JsonResponse( $request_result, $code );
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks both of you. As you can tell I'm a noob who is taking over for somebody else at work and using their code as a base.
A simple if clause with 'AND' Logical gates would do the trick.
Or am I missing something?