Trying to echo a variable ( $i) into another variable

I have a special form I have been making that uses some cusotm post types in wordpress. At one point I need to echo a variable $i into an if statement.

There is some validation stuff at the top that will look like this and the code in the loop is below. Pretty much I have been trying to get the majorCause1Error to be majorCause $i Error if you know what I mean, so all up it will be like 1-13

Read More

Edit: Sorry If it is hard to see what I am asking, I am finding it really hard to word my problem.
So there is a loop running around the li tags and it echos $i into the name etc so it becomes majorCause1 then next one majorCause2 and the next one magjorCause3 etc etc

Under the labels there is an if statement that is like – if($majorCause1Error !=”) { do something } – I want this to be like if($majorCause1Error !=”){} and then the next one be like if($majorCause2Error !=”){} and then if($majorCause3Error !=”){}

Does this make more sense?

Here is a link to the site http://www.foresightaus.com.au/form/

if(trim($_POST['majorCause1']) === '') {
    $majorCause1Error = "Please enter a major cause.";
    $hasError = true;
} else {
    $majorCause1 = trim($_POST['majorCause1']);
}

if(trim($_POST['majorCause2']) === '') {
    $majorCause2Error = "Please enter a major cause.";
    $hasError = true;
} else {
    $majorCause2 = trim($_POST['majorCause2']);
}

<li class="fill-in">
    <label for="majorCause<?php echo($i); ?>"><?php echo($j); ?>. State one major cause:</label>
    <input type="text" name="majorCause<?php echo($i); ?>" id="majorCause<?php echo($i); ?>" value=""/>
    <?php if($majorCause1Error != '') { ?>
        <span class="error"><?=$majorCause1Error;?></span>
    <?php } ?>  
</li>

Related posts

Leave a Reply

1 comment