How to set value 0 (zero) in input? - forms

I made ​​a simple form to arrange the structure of the html code.
I got a problem when I want to make the number 0 in the input tag value without clear it after submit.
value on this input can be changed, but I want to set the default to be 0 = This will be 0px;
as an example -> style="padding: px px px px" it is the wrong structure, this should be -> style="padding: 0px 0px 0px 0px"
I make the value to be like this.
this will prevent the value lost after submitted.
how do i give value 0, but does not remove this feature?
//Edited, It just a simple for example://
<?php
echo "style='padding:".$ul_padding_top.$ul_pd_px." ".$ul_padding_right.$ul_pd_px." ".$ul_padding_bottom.$ul_pd_px." ".$ul_padding_left.$ul_pd_px.";'";
?>
<form action="/" method="post">
<input type="text" name="ul_padding_top" value="<?php echo isset($_POST['ul_padding_top']) ? $_POST['ul_padding_top'] : '' ?>" />px = padding-top<br/>
<input type="text" name="ul_padding_right" value="<?php echo isset($_POST['ul_padding_right']) ? $_POST['ul_padding_right'] : '' ?>" />px = padding-right<br/>
<input type="text" name="ul_padding_bottom" value="<?php echo isset($_POST['ul_padding_bottom']) ? $_POST['ul_padding_bottom'] : '' ?>" />px = padding-bottom<br/>
<input type="text" name="ul_padding_left" value="<?php echo isset($_POST['ul_padding_left']) ? $_POST['ul_padding_left'] : '' ?>" />px = padding-left<br/>
<input class="foo_ul_pd" type="hidden" name="ul_pd_px" value="px" <?php if(isset($_POST['ul_pd_px'])) echo "checked='checked'"; ?> /> padding value "px"<br/>
<input class="button" type="submit" value="Generate!">
</form>

I think your looking for
<input class="foo" type="checkbox" name="padding" checked />
Or you could use Jquery
$('.foo').prop('checked',true);
And to read it with Jquery can do
$('.foo').prop('checked');
EDIT:
Just re-read your description you say you wish to put the value 0 in a field you will need to change type="checkbox" to type="text" at which point you can do value="0"
EDIT 2:
This won't work
<input class="foo_ul_pd" type="hidden" name="ul_pd_px" value="px" <?php if(isset($_POST['ul_pd_px'])) echo "checked='checked'"; ?> />
a input type="hidden" is basically a type="text" so you would just need to use
<input class="foo_ul_pd" type="hidden" name="ul_pd_px" value="0" />

Related

Undefined array key error in Codeigniter 4 even when var_dump() is showing data

This is my Controller Code:
public function edit_manpower($Manpower_id=null)
{
$session = session();
$db = \Config\Database::connect();
$builder = $db->table('Manpower');
$builder->select('Manpower.*');
$builder->where('Manpower_id', $Manpower_id);
$query = $builder->get();
$data['row'] = $query->getResultArray();
return view("admin/update_manpower_form",$data);
}
This is my View Code where the error arises:
<form action = "<?php echo site_url('Admin/updatemanpower/'.$row['Manpower_id']);?>" method=
"post" enctype="multipart/form-data">
<input type="hidden" name="_method" value="PUT"/>
<div class="form-group">
<div class=required-field><label for="Name">NAME:</label></div>
<input type="text" class="form-control" placeholder="Enter name" id="Name" value="<?php echo
$row['Name'];?>" name="Name" autocomplete="off">
</div>
<br>
<div class="form-group">
<div class=required-field><label for="Contact_no">CONTACT NUMBER:</label></div>
<input type="text" class="form-control" placeholder="Enter phone number" id="Contact_no"
value="<?php echo $row['Contact_no'];?>" name="Contact_no" autocomplete="off">
</div>
<br>
When I place the following line at the top of View, the required data is displayed:
<?php var_dump($row); ?>
The error message displayed is:
Undefined array key "Manpower_id"
APPPATH\Views\admin\update_manpower_form.php at line 65
64 <br><br>
65 <form action = "<?php echo site_url('Admin/updatemanpower/'.$row['Manpower_id']);?>"
method= "post" enctype="multipart/form-data">
66 <input type="hidden" name="_method" value="PUT"/>
I am unable to find what I am doing wrong. Kindly help.
Your $row maybe an Object array.
#std[]

How to generate new upload button in real time

I have a simple contact form with a file upload option built in. However, it only has 1 "Browse" button, and I want there to be unlimited. But instead of duplicating the "Browse" code a bunch of times, I'd rather it create a NEW browse button once the user has used the old one (uploaded a file).
How do I create another button in real-time?
Here is a full demo of the form: http://www.html-form-guide.com/files/contact-form/contact-form-attachment-1/contactform.php
The form's code is below, my question relates to upload button. Thank you!!
<form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' enctype="multipart/form-data" accept-charset='UTF-8'>
<fieldset >
<legend>Describe the issue:</legend>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text' class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
<div class='short_explanation'>*All fields are required.</div>
<div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
<div class='container'>
<label for='name' >Full Name: </label><br/>
<input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
<span id='contactus_name_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='email' >Email Address:</label><br/>
<input type='text' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email') ?>' maxlength="50" /><br/>
<span id='contactus_email_errorloc' class='error'></span>
</div>
<div class='container'>
<label for='message' >Message:</label><br/>
<span id='contactus_message_errorloc' class='error'></span>
<textarea rows="10" cols="50" name='message' id='message'><?php echo $formproc->SafeDisplay('message') ?></textarea>
</div>
<div class='container'>
<label for='photo' >Upload your file:</label><br/>
<input type="file" name='photo' id='photo' /><br/>
<span id='contactus_photo_errorloc' class='error'></span>
</div>
<div class='container'>
<input type='submit' name='Submit' value='Submit' />
</div>
</fieldset>
</form>
Suppose you have one upload button in html like this:
<body>
<form>
<input type="file" name="upload1" id="upload1"/>
</form>
</body>
Then, you can add another upload button on Click event on previous button using jquery:
$(function(){
$('#upload1').on('click',function(){
var r= $('<input type="file" value="new button"/>');
$("form").append(r);
});
});
JSFIDDLE DEMO HERE
If you are not familiar with how to use Jquery, This is the place where you can learn:Learn jquery

Input elements not being posted with HTML5

I'm working on a test HTML5 login form and have the form set up like so:
<form id="login" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<h1>Log In</h1>
<fieldset id="inputs">
<input id="username" type="text" placeholder="Username" autofocus required>
<input id="password" type="password" placeholder="Password" required>
</fieldset>
<fieldset id="actions">
<input type="submit" id="submit" name="submit_data" value="Log in">
</fieldset>
</form>
When clicking Submit, the form is posted back to the same page. When I print the array of POSTed elements, I'm only seeing one for 'submit_data'. 'username' and 'password' are not coming through.
Where am I going wrong?
You haven't specified names for your inputs, e.g.
<form id="login" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<h1>Log In</h1>
<fieldset id="inputs">
<input id="username" type="text" name="username" placeholder="Username" autofocus required>
<input id="password" name="password" type="password" placeholder="Password" required>
</fieldset>
<fieldset id="actions">
<input type="submit" id="submit" name="submit_data" value="Log in">
</fieldset>
</form>
That might fix this problem.
Can you just perform a check for isset($_POST['username']) and isset($_POST['password']) instead of the print_r (which I assume you are using)?
<input type="..." NAME="username" ..> You haven't set var name.
Also instead of placeholder, set value="Username" and value="Password". There may not be any value passed if just using placeholder. See this test: http://www.w3schools.com/html5/tryit.asp?filename=tryhtml5_input_placeholder
As you submit without anything, no value is passed. Once you type something in, value is passed.

mark the input box red if the required field of a form is not filled

i'm using Codeigniter. i have a form which takes information about users. What i want to do is to check whether all the required fields are filled up or not.If any of the required fields is not filled up i want mark that input box red. Right now my codes only check if the required fields are filled up or not. if not it says the "field is required" but how to mark input box.I'm a bit confused how to do this thing.Can somebody help me out with a little hint. Thanks.
the view for my form:
<?php
$attributes = array('class' => '', 'id' => '');
echo form_open('register', $attributes); ?>
<p>
<label for="name">Name <span class="required">*</span></label>
<?php echo form_error('name'); ?>
<br /><input id="name" type="text" name="name" value="<?php
echo set_value('name'); ?>"
</p>
<p>
<label for="username">Username <span class="required">*</span></label>
<?php echo form_error('username'); ?>
<br /><input id="username" type="text" name="username" value="<?php echo set_value('username'); ?>"
</p>
<p>
<label for="password">Password <span class="required">*</span></label>
<?php echo form_error('password'); ?>
<br /><input id="password" type="password" name="password" value="<?php echo set_value('password'); ?>"
</p>
<p>
<label for="email">Email <span class="required">*</span></label>
<?php echo form_error('email'); ?>
<br /><input id="email" type="text" name="email" value="<?php echo set_value('email'); ?>"
</p>
<p>
<label for="phone">Phone</label>
<?php echo form_error('phone'); ?>
<br /><input id="phone" type="text" name="phone" value="<?php echo set_value('phone'); ?>"
</p>
</p>
<p>
<input type="submit" value="Submit information" class="formbutton"/>
</p>
<?php echo form_close(); ?>
Generally, I'd recommend creating an textInputError class where you adjust the input style, and then apply it based on the existence of the error...
class="<?php echo (form_error('username') ? 'textInputError' : '') ?>"
in place in the input element...
<input id="username" type="text" name="username" value="<?php echo set_value('username'); ?>" class="<?php echo (form_error('username') ? 'textInputError' : '') ?>">

Codeigniter Form Helper Duplicate from_hidden?

Im totally stumped.. Im creating some form elements using the CI form helper and for some weird reason, its creating a duplicate version.
Here is my PHP
<div id="receiveInventoryItemDetails">
<p><?php echo form_open('#', array("class" => "nyroModal form label-inline"));?></p>
<?php echo form_hidden('item_id', '', "readonly = true"); ?>
<?php echo form_hidden('purchase_order_id', '', "readonly = true"); ?>
<p><?php echo form_label('Item Name', 'item_name');?><?php echo form_input('item_name', '', "readonly = true"); ?></p>
<p><?php echo form_label('Item QTY', 'item_qty');?><?php echo form_input('item_qty', ''); ?></p>
<?php echo form_close();?>
</div>
<div class="buttonrow">
<button class="btn-sec" onclick="inventoryC.receiveSubmitItem();"><span>Add To Inventory</span></button>
</div>
Here is the HTML output
<div id="receiveInventoryItemDetails">
<p><form action="https://mysite.com/#.abl" method="post" accept-charset="utf-8" class="nyroModal form label-inline"></p>
<input type="hidden" name="item_id" value="" />
<input type="hidden" name="item_id" value="" />
<input type="hidden" name="purchase_order_id" value="" />
<p><label for="item_name">Item Name</label><input type="text" name="item_name" value="" readonly = true /></p>
<p><label for="item_qty">Item QTY</label><input type="text" name="item_qty" value="" /></p>
</form>
</div>
<div class="buttonrow">
<button class="btn-sec" onclick="inventoryC.receiveSubmitItem();"><span>Add To Inventory</span></button>
</div>
You can't use html attributes via third parameter. Look at form helper source code
This should be work:
<?php echo form_hidden('item_id', ''); ?>