Jump to content

Help with Php conditions


joy1

Recommended Posts

I have created a form in wich a user inputs until 5 ranges of numbers

<tr>

<td width='270' align='right'>Εύρος1__Από: </td>

<td><input type='text' name='fromNum' size='20' /></td>

<td width='270' align='right'>Εως: </td>

<td><input type='text' name='toNum' size='20'/></td>

</tr>

<tr>

<td width='270' align='right'>Εύρος2__Από: </td>

<td><input type='text' name='fromNum2' size='20' /></td>

<td width='270' align='right'>Εως: </td>

<td><input type='text' name='toNum2' size='20'/></td>

</tr>

<tr> the same and for ranges 3,4,5

 

i put a constraint for the ranges

$regExpNum = '/^[0-9]{6}$/';

$regExpNum2 = '/^[0-9]{6}$/';

$regExpNum3 = '/^[0-9]{6}$/';

$regExpNum4 = '/^[0-9]{6}$/';

$regExpNum5 = '/^[0-9]{6}$/';

 

$validfromNum = preg_match($regExpNum,$_POST['fromNum'],$matchesfrom);

$validtoNum = preg_match($regExpNum,$_POST['toNum'],$matchesto);

$validfromNum2 = preg_match($regExpNum2,$_POST['fromNum2'],$matchesfrom2);

$validtoNum2 = preg_match($regExpNum2,$_POST['toNum2'],$matchesto2);

$validfromNum3 = preg_match($regExpNum3,$_POST['fromNum3'],$matchesfrom3);

$validtoNum3 = preg_match($regExpNum3,$_POST['toNum3'],$matchesto3);

$validfromNum4 = preg_match($regExpNum4,$_POST['fromNum4'],$matchesfrom4);

$validtoNum4 = preg_match($regExpNum4,$_POST['toNum4'],$matchesto4);

$validfromNum5 = preg_match($regExpNum5,$_POST['fromNum5'],$matchesfrom5);

$validtoNum5 = preg_match($regExpNum5,$_POST['toNum5'],$matchesto5);

 

i want to wright a combination of contitions for the five ranges.

for one range here is the code, but could you please help me to write a code for all of them?

 

 

$regExpNum = '/^[0-9]{6}$/';

$validfromNum = reg_match($regExpNum,$_POST['fromNum'],$matchesfrom);

$validtoNum = preg_match($regExpNum,$_POST['toNum'],$matchesto);

 

$errorMsg='';

 

if (!$validfromNum || !$validtoNum) {

if (!$_POST['fromNum'] && !$_POST['toNum']) {

$errorMsg="μήνυμα";

$htmlData['errorMsg']= $errorMsg;

$this->loadPage($htmlData);

return false;

} else if ($validtoNum && !$_POST['fromNum']) {

set_time_limit(240);

$data = $this->R100WorkOrder->GetWoRangeData($_POST['toNum'], $_POST['toNum']);

} else if ($validfromNum && !$_POST['toNum']) {

set_time_limit(240);

$data = $this->R100WorkOrder->GetWoRangeData($_POST['fromNum'], $_POST['fromNum']);

 

} else {

$errorMsg="μήνυμα";

$htmlData['errorMsg']= $errorMsg;

$this->loadPage($htmlData);

return false;

}

} else {

####################################################### Form Validation ################################################# End

if ($_POST['fromNum'] > $_POST['toNum']) {

$errorMsg="μήνυμα ";

$htmlData['errorMsg']= $errorMsg;

$this->loadPage($htmlData);

return false;

} else if ($_POST['toNum'] - $_POST['fromNum'] > 100 ) {

$errorMsg="μήνυμα";

$htmlData['errorMsg']= $errorMsg;

$this->loadPage($htmlData);

return false;

} else {

set_time_limit(240);

$data = $this->R100WorkOrder->GetWoRangeData($_POST['fromNum'], $_POST['toNum']);

}

}

Link to comment
https://forums.phpfreaks.com/topic/219573-help-with-php-conditions/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.