actually, i want to display back all checked value in checkbox..In my form, there is some checkbox element where the user should check necessary value b4 submit the form....My problem is, once the user has submit the from, i can't retrieved only checked value.....it display all value including unchecked value in checkbox....so, if anyone can help me, it would be great....thanks in advance......

Dani AI

Generated

A clear, reliable pattern for a multi-step form solves this: name checkboxes as an array, read only the posted array on the confirmation page, and forward only those checked values (for example as hidden inputs) to the final save step. and asked for code, so below is a minimal, safe pattern you can adapt.

HTML (collector form):

<form action="confirm.php" method="post">
  <label><input type="checkbox" name="features[]" value="alpha"> Alpha</label>
  <label><input type="checkbox" name="features[]" value="beta"> Beta</label>
  <label><input type="checkbox" name="features[]" value="gamma"> Gamma</label>
  <button type="submit">Continue</button>
</form>

Confirmation page: read only the submitted array and include one hidden input per checked value to pass them to the save step. Do not disable the inputs you expect to submit.

<?php
$selected = isset($_POST['features']) ? $_POST['features'] : array();
?>
<form method="post" action="save.php">
  <?php foreach ($selected as $v): ?>
    <div><?php echo htmlspecialchars($v); ?></div>
    <input type="hidden" name="features[]" value="<?php echo htmlspecialchars($v, ENT_QUOTES); ?>">
  <?php endforeach; ?>
  <button type="submit">Save</button>
</form>

Notes and common pitfalls: use the [] suffix so PHP receives an array; disabled form controls are not submitted, so avoid disabling the checkboxes if you want them posted; do not add hidden inputs for unchecked options (that will make them appear checked on submit); consider session storage if you prefer not to generate many hidden fields. This pattern ensures only the actual checked values are displayed and saved.

Recommended Answers

All 3 Replies

Can you post your code ?

will u send me code

this is the sequence of the code.....the user will create project (createproject.php) then once he click submit, the from will be displayed for confirmation (displaycreateproject.php) and lastly, when they submit the confirmation form , the data will be save in the database (saveproject.php)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.