How To Post Text To Html With Php
Okay so what I am after for here is to check if a checkbox has been ticked, if it has, then I would like to add the text into a
- class named, let's say, 'confirmed', so &
Solution 1:
Alright so when you tick a checkbox it should return a value through the $_POST which is 1 or 0 on submit. You may modify your template like this:
<?phpif ($_POST['checkbox1']) {
$class = 'confirmed';
}
else {
$class = 'unconfirmed';
}
?><body><divid="content"><divclass="jumbotron"><h1>Is there football on Wednesday?</h1><h2>Yes.</h2></div><divclass="alert alert-info"role="alert">Confirmed Players</div><ulclass="list-group <?phpecho$class; ?>"><liclass="list-group-item">
Lorem Ipsor
</li></ul><divclass="alert alert-danger"role="alert">Unconfirmed Players</div></div><!--form--><formaction="check.php"method="POST"><inputtype="checkbox"name="checkbox1" /><inputtype="submit" /></form></body>
To be sure you can always var_dump the $_POST to see what is coming through in it and modify your if statement to be more accurate, it should return 1 or 0 iirc.
Solution 2:
Without using AJAX you can try nesting php code like this:
<ulclass="list-group"><liclass="list-group-item"><?phpif (isset($_POST["checkbox1"])){
//write to <ul> class confirmed
}
?></li></ul><divclass="alert alert-danger"role="alert">Unconfirmed Players</div><liclass="list-group-item"><?phpif (!isset($_POST["checkbox1"])){
//write to <ul> class unconfirmed
}
?></li>
Post a Comment for "How To Post Text To Html With Php"