Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic if-statement with variables?
    primarykey
    data
    text
    <p>I'm trying to create a dynamic if-statement. The reason I want to do this, is because I need to check server-sided whether inputfields match my regex and are not empty. However, some of my inputfields can be removed in my CMS, meaning there would be more/less inputfields accordingly.</p> <p>Ideally I would add variables in my if-statement but I'm not 100% sure if that's allowed, so perhaps I would need an other way to solve this problem. Here's what I tried:</p> <pre><code>if ($f_naw['streetname'] == 1) { $streetname= $_POST['streetname']; //Used in INSERT query $cstreetname = " || $_POST['streetname'] == ''"; //Used to check if field is empty $pstreetname = " || !preg_match($streetnameReg,$_POST['streetname'])"; //Used to check if it matches my regex } else { //These variables define variables if inputfields are not shown $streetname= ''; //No streetname means it's excluded in INSERT query $cstreetname = ''; //Not needed in check $pstreetname = ''; //Also not needed in check } // more of these if/else statements if ($_POST['firstname'] == '' || $_POST['lastname'] == '' || $_POST['email'] == '' $cstreetname $cpostalcode $chometown $ctelnr $csex $cdateofbirth) { echo 'One of the fields is empty.'; header('refresh:3;url=index.php'); } else { //Regex check, after that more code } </code></pre> <p>My idea was to check if a specific field is shown on the front-end and in that case I'm creating some variables that I want to paste in my if-statements.</p> <p>I'm getting an error saying Server error meaning my php-code would be invalid.</p> <p>Is it even possible at all to make a dynamic if-statement? If yes, at what part am I failing?</p> <p>Help is much appreciated! Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload