I hope I can explain this right but the image should make it clear (hopefully).
In the admin side of my site, I have different fields for products, but I do not want the fields shown to the frontend user if the show checkbox isn't checked. As seen in my image below.
Now my issue I am not getting is should I have a row name for every checkbox or can I use just one like show.
simplified can I use something like this
<div class="form-group">
<label class="col-md-3">Sales Price</label>
<div class="col-md-8">
<input type="text" name="price" value="<?php echo $row['price']; ?>" class="form-control" />
</div> <!-- /.col -->
<input type="checkbox" value="1" <?php echo ($row['show'] == 1) ? 'checked="checked"' : ''; ?> name="show">
</div> <!-- /.form-group -->
or do I have to use something like this
<div class="form-group">
<label class="col-md-3">Sales Price</label>
<div class="col-md-8">
<input type="text" name="price" value="<?php echo $row['price']; ?>" class="form-control" />
</div> <!-- /.col -->
<input type="checkbox" value="1" <?php echo ($row['showprice'] == 1) ? 'checked="checked"' : ''; ?> name="showprice">
</div> <!-- /.form-group -->
Here is what I am after using an image.
As for making the content show on the frontend Here is the code for that. This is set up now to NOT show if the data is missing. (I haven't set it up to show about the checkboxes until I figure out what to use)
<?php if (isset($model) && !empty($model)) : ?>
<li class="element element-text">
<strong>Model #: </strong>
<?php echo $model;?>
</li>
<?php endif; ?>
I thought about using something like this, but again I am not sure if I can use a single checkbox (show) for all the variables.
<div style="display:<?= ($offer === 1) ? 'block' : 'none'; ?>"></div>
Again, I hope I explained this good enough and any help would be greatly appreciated.
Related
I'm trying to create a custom template for my phpmaker project, I tried every possible solution to change the default CSS for labels but I cannot get input: focus selects input when it gets focus and Selector input: not(: focus): valid select input if valid input did not focus. Please suggest some ways to solve this issue
<div id="r_tennam" class="col-sm">
<div class="floating-group">
<label id="elh_tender_tennam" for="x_tennam" class="col-sm col-form-label ew-label"><?php echo $tender_add->tennam->caption() ?><?php echo $tender_add->tennam->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
<div <?php echo $tender_add->tennam->cellAttributes() ?>>
<span id="el_tender_tennam">
<input type="text" data-table="tender" data-field="x_tennam" name="x_tennam" id="x_tennam" maxlength="200" placeholder=" " value="<?php echo $tender_add->tennam->EditValue ?>"<?php echo $tender_add->tennam->editAttributes() ?>>
</span>
</div>
</div>
</div>
I am android developer and making one admin panel for one of my android application. I know very basic PHP. currently I am displaying input field with value and user can change with text input and can save value with submit button. Its like below
<div class="form-group">
<label class="col-md-3 control-label">Admob On/off :-</label>
<div class="col-md-6">
<input type="text" name="ads_status" id="ads_status" value="<?php echo $settings_row['ads_status'];?>" class="form-control">
</div>
</div>
Instead of input value I want show dropdown menu with two item called on and off. When user load page it should show value based on previous save. Like if user have made setting on it must display on. I am displaying value now from database. Let me know if anyone can suggest me what Should I do for it. Thanks
<div class="form-group">
<label class="col-md-3 control-label">Admob On/off :-</label>
<div class="col-md-6">
<select class="form-control " type="text" name="ads_status" >
<option value="on" <?php if($settings_row['ads_status']== 'on') echo "selected = 'selected'" ?> >On</option>
<option value="off" <?php if($settings_row['ads_status'] == 'off') echo "selected = 'selected'" ?> >Off</option>
</select>
</div>
</div>
I hope this will hep you.
I have a form and a checkbox. By click on the checkbox, a div within some other divs will show up or hide. This works! But, if i visit my page with an id like xxxxx.php?id=10, the checkbox is checked but the divs are hide. if i click on the checkbox, the divs will show up, but the checkbox is unchecked (bad for e.g. mysql updates).. hope anyone can help me by this issue..
Here my code:
$(document).ready(function() {
$('#Show').hide();
$("input[name=mycheckbox]").click(function () {
$('#Show').toggle();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="form">
<div class="form-group">
<div class="form-group">
<div class="checkbox-inline">
<label>
<input type="checkbox" name="mycheckbox" id="mycheckbox" value="yes"> my option
</label>
</div>
</div>
</div>
<div id="Show">
<div class="form-group">
<label for="textinput" class="control-label">Company </label>
<div class="">
<input type="text" class="form-control" name="name" id="name" placeholder="" value="">
</div>
</div>
</div>
</form>
My input field have this code (php doesn't work in the snippet):
<input type="checkbox" name="mycheckbox" id="mycheckbox" value="yes" <?php if (isset($_GET['id'])) {echo $row->mycheckbox == "yes" ? 'checked="checked"' : "";}?>
thanks for your help!
I would recommend to use change event, trigger using .trigger('change') on page load so that the div in sync with the state of checkbox element.
Also you should .toggle(display)
$("input[name=mycheckbox]").change(function () {
$('#Show').toggle(this.checked);
}).trigger('change');
I have a form which is posted via php and if I get a error it highlights only the input field red. What I would like to do or know if there is a way to do is highlight the whole div field which contains the select field and everything and show that this whole div has a error.
Here is my html code.
<div class="form-group">
<div class="<?php if(form_error('fullname')!= null){echo ' has-error';} ?>">
<label class="col-md-4 control-label">
<?php echo lang("full_name"); ?>
</label>
<div class="col-md-8">
<input type="text" name="fullname" class="form-control" value="<?php if (isset($userinfo['Fullname'])) {echo $userinfo['Fullname'];} ?>" placeholder="<?php echo lang(" fullname "); ?>">
</div>
</div>
</div>
Right now it only highlights input field but I want it to highlight the whole div form-group.
Since you are using bootstrap, you could try this. Please change
<div class="form-group">
to
<div class="form-group alert alert-danger">
Try this.
<div class="form-group <?php if(form_error('fullname')!= null){echo ' bg-danger';} ?>">
<div class="<?php if(form_error('fullname')!= null){echo ' has-error';} ?>">
<label class="col-md-4 control-label">
<?php echo lang("full_name"); ?>
</label>
<div class="col-md-8">
<input type="text" name="fullname" class="form-control" value="<?php if (isset($userinfo['Fullname'])) {echo $userinfo['Fullname'];} ?>" placeholder="<?php echo lang(" fullname "); ?>">
</div>
</div>
</div>
What I have done is used, .bg-danger, one of the Bootstrap Contextual Classes based on the same if condition you have to apply the has-error class.
I have a HTML Form that uses partial PHP to grab the value, the form is basically like an edit account details form.
The Problem
I cannot work out why the form is not working and when using notepad++ to edit my code if I click on the it shows the start to be a DIV which just confuses the matter even more... When submitting the form it takes you back to the form page with no message so I am lost for a reason..
Form Page
<form method="POST" action="dev.php">
<!-- Row -->
<div class="row-fluid">
<!-- Column -->
<div class="span6">
<!-- Group -->
<div class="control-group">
<label class="control-label" for="fname">First name</label>
<div class="controls">
<input type="text" name="fname" id="fname" value="<?php echo $user_fname; ?>" class="span10" />
<span style="margin: 0;" class="btn-action single glyphicons circle_question_mark" data-toggle="tooltip" data-placement="top" data-original-title="First name is mandatory"><i></i></span>
</div>
</div>
<!-- // Group END -->
<!-- Group -->
<div class="control-group">
<label class="control-label" for="lname">Last name</label>
<div class="controls">
<input type="text" name="lname" id="lname" value="<?php echo $user_sname; ?>" class="span10" />
<span style="margin: 0;" class="btn-action single glyphicons circle_question_mark" data-toggle="tooltip" data-placement="top" data-original-title="Last name is mandatory"><i></i></span>
</div>
</div>
<!-- // Group END -->
</div>
<!-- // Column END -->
<!-- Column -->
<div class="span6">
<!-- Group -->
<div class="control-group">
<label class="control-label" for="email">Email Address</label>
<div class="controls">
<input type="text" name="email" id="email" value="<?php echo $user_email; ?>" class="span10" />
<span style="margin: 0;" class="btn-action single glyphicons circle_question_mark" data-toggle="tooltip" data-placement="top" data-original-title="First name is mandatory"><i></i></span>
</div>
</div>
<!-- // Group END -->
<!-- Group -->
<div class="control-group">
<label class="control-label" for="phonenumber" >Phone Number:</label>
<div class="controls">
<input type="text" name="phonenumber" id="phonenumber" value="<?php echo $user_number; ?>" class="span10" />
</div>
</div>
<!-- // Group END -->
</div>
<!-- // Column END -->
</div>
<!-- // Row END -->
<div class="separator line bottom"></div>
<!-- Group -->
<div class="control-group row-fluid">
<label class="control-label" for="bio">About me</label>
<div class="controls">
<textarea id="bio" name="bio" class="span12" rows="5"><?php echo $user_bio;?></textarea>
</div>
</div>
<!-- Form actions -->
<div class="form-actions" style="margin: 0;">
<button type="submit" id="accountdetails" name="accountdetails" class="btn btn-icon btn-primary glyphicons circle_ok"><i></i>Save changes</button>
</div>
</div>
</form>
<!-- // Form actions END -->
dev.php
if (isset($_POST['accountdetails'])) {
if (isset($_POST['fname']) || isset($_POST['lname']) || isset($_POST['email']) || isset($_POST['phonenumber']) || isset($_POST['bio'])) {
die ("HERE");
};
};
I probably need to drink more Coffee but I cannot for the life of me work out why it is not working.
Any help would be appreciated!
Thanks in advance.
EDIT
I put the name's in and this did not help, now the URL of the page shows this:
update.php?fname=Aaron&lname=Hatton&email=me%40aaronhatton.co.uk&phonenumber=0123456789&bio=+18+%7C+London+%7C+Taken&accountdetails=
any ideas?
One: do what Fred said (name attributes on your input tags).
Two: You're missing the </form> tag at the end.
Your form page seems correct, however, since the form updates the user data, look what the dev.php code is doing:
isset() function returns true if the value is set and you manual set the fields so it will evaluate to true.
and in your if statement you are ORing all the conditions so as soon as it finds 1 true condition, it will go into the if statement body and execute die which will do nothing.
so if you want to test, instead of using die, try echo "here" to see if a message is printed.
So I found out the form works perfect and there was some AJAX being used by another coder, removed and surprise surprise it works perfectly!
Damn co-workers!
Thanks to all that helped!