Concatenation help - newbie complex

Hello all,

I have the following snipped:

        $id = (isset($_GET['id'])) ? (int)$_GET['id'] : 0;
        echo "<input type='hidden' name='hiddenId' value='$id'>";

However, I need to preserve the value of this hidden field, after post.
So instead of just having $id, I believe I must have, on the value element, the following:

<?php echo (isset($_POST['hiddenId'])) ? $_POST['hiddenId'] : $id; ?>

I’ve tried something like this, no joy.

        $id = (isset($_GET['id'])) ? (int)$_GET['id'] : 0;
        echo '<input type="hidden" name="hiddenId" value="'<?php echo (isset($_POST[\\'hiddenId\\'])) ? $_POST[\\'hiddenId\\'] : $id; ?>'">';

I’m missing something obvious isn’t it?
Can I have your help here please.



No worries, I’m here to help :slight_smile:

:slight_smile: It was rubbish ScallioXTX sorry for wasting your time.

A simple

<input type='hidden' name='hiddenId' value='<?php echo (isset($_POST['hiddenId'])) ? $_POST['hiddenId'] : $id; ?>'>

will do it.

And that $id need to get out of my forms page anyway.

Thanks for the concatenation help :wink:


$id = (isset($_GET['id'])) ? (int)$_GET['id'] : 0;
echo '<input type="hidden" name="hiddenId" value="'. (isset($_POST['hiddenId']) ? $_POST['hiddenId'] : $id) . '">';