cant place spaces between radio button options in cakephp 3.2 - html

In Cakephp3.2 I cant place spaces between radio buttons. I am sure there is an easy way.
Here is an example of what I am talking about from my test server, check the radio button area in Grammar section about 2/3rds down page.
http://andrewt.com.au/crm/students/studentassessment-eng7/35730
My code
<?php $opt1q1=' I wanted to watch TV, but the electricity went out unexpectedly.';
?>
<br>
<h3><?php echo 'Task 3: Grammar' ?> </h3>
<div class='alert alert-info'><?php echo '1 )'.$opt1q1; ?> </div>
<?php echo $this->Form->radio( 'a16', ['text'=>'a) noun', 'b) verb ','c) preposition ', 'd) pronoun ' ],
['default' =>$assessment['a16'] ,'style' => 'padding-left:5px;' ] );
The docs didnt help either and its maybe because I have an older version cakephp?
https://book.cakephp.org/3/en/views/helpers/form.html#creating-radio-buttons
Didnt work
space between the radio button and label Cakephp

i think what you are looking for are link breaks?
How to add a line break within echo in PHP?
https://www.w3schools.com/php/func_string_nl2br.asp

<input type="hidden" name="a16" value="" class="form-control"><label for="a16-0">
<input type="radio" name="a16" value="0" <?php echo $assessment['a16']==0 ?' checked=checked':'' ?> >a) noun</label><label for="a16-0">
<input type="radio" name="a16" value="1" <?php echo $assessment['a16']==1 ?' checked=checked':'' ?> >b) verb</label><label for="a16-1">
<input type="radio" name="a16" value="2" <?php echo $assessment['a16']==2 ?' checked=checked':'' ?> >c)preposition</label><label for="a16-2">
<input type="radio" name="a16" value="3" <?php echo $assessment['a16']==3 ?' checked=checked':'' ?> >d)pronoun </label><label for="a16-3">
<style>
label{
margin-left: 16px;
}
</style>

Related

How to show double quote in input tag?

How to show double quote in input tag ?
my $test is i test "hello"
and input like this
<input name="test" type="text" value="<?PHP echo $test; ?>">
When test code in input show only i test
How can i do for show i test "hello" in input tag ?
Try to use htmlspecialchars or use htmlentities
<input name="test" type="text" value="<?php echo htmlspecialchars($test); ?>">
<input name="test" type="text" value="<?php echo htmlentities($test); ?>">
Or by using PHP echo you can do it
<?php echo '<input name="test" type="text" value="'.$test.'">'; ?>
use html_entity_decode since you're using php like so:
<input name="test" type="text" value="<?PHP echo html_entity_decode($test); ?>">

<input> and <select> inside one <label> tag

Currently we have a input and a select inside a label.
We want to make the entire label clickable, so that this will select the radio button.
After selection the radio button, the underlaying div will show up where the user can use the select.
This code works great on Safari and Chrome, but not on Firefox.
In Firefox the user can not use the select, this will directly popback up.
How can we fix this problem?
<label class="formListBlock">
<input id="method" value="<?php echo $_code ?>" type="radio" onclick="payment.switchMethod('<?php echo $_code ?>')" checked="checked"<?php endif; ?> class="radio"/>
<div class="formListBlock-selector">
<ul class="form-list ops-form-list" id="payment_form_ops_iDeal" style="display:none;">
<li>
<select name="payment" id="ops" class="required-entry">
<option value=""><?php echo $this->__('--Please Select--')?></option>
<?php foreach ($issuers as $key => $value): ?>
<option value=<?php echo $this->escapeHtml($key) ?>>
<?php echo $this->escapeHtml($value) ?>
</option>
<?php endforeach; ?>
</select>
</li>
</ul>
</div>
</label>
Why do you put such complex HTML inside a <label>? Normally, a <label> just needs a for= attribute to point to the id of an <input>. This should be enough to make the input get focus when the user clicks the label. You can bind to the focus event and continue from there.

How to have my radio button stay selected after the submission button?

I'm new to coding and have a questionnaire that requires a selection of two choice... I can chose the selection and have it output the correct response, however, the choice chosen does not retain. How can i make it stay after a user hits the submit button? I've tried to research it and used several different format but it was still not working. Not sure if it's my syntax or I'm just do not have the right coding.
I've provided a copy of the code.
<form method="post" action="">
<p><span class="error">* required field.</span></p>
<p>What is the pay period reported by Company X:</p>
<input type="radio" name="payPeriod" value="1" <?php if (isset($_POST['payPeriod']) && $_POST['payPeriod']=='biWeekly') echo ' checked="checked"';?> />Bi-Weekly
<input type="radio" name="payPeriod" value="2" <?php if (isset($_POST['payPeriod']) && $_POST['payPeriod']=='semiMonthly') echo ' checked="checked"';?> />Semi-Monthly
<span class="error">* <?php echo $payPeriodErr;?></span>
<br/>
<p>What is the clients response to pay period:<br/>
(How often do you get paid, once every two weeks or twice a month?)</p>
<input type="radio" name="pay_Period" value="1" <?php if (isset($_POST['pay_Period']) && $_POST['pay_Period']=='bi_Weekly') echo ' checked="checked"';?> />Every two weeks
<input type="radio" name="pay_Period" value="2" <?php if (isset($_POST['pay_Period']) && $_POST['pay_Period']=='semi_Monthly') echo ' checked="checked"';?> />Twice a month
<span class="error">* <?php echo $pay_PeriodErr;?></span>
<br/>
<p>Does your pay day result on the same days of the week:<br/>
(i.e.: Every pay checks are paid on Fridays.)</p>
<input type="radio" name="payDay" value="1" <?php if (isset($_POST['payDay']) && $_POST['payDay']=='yes') echo ' checked="checked"';?> />Yes
<input type="radio" name="payDay" value="2" <?php if (isset($_POST['payDay']) && $_POST['payDay']=='no') echo ' checked="checked"';?> />No
<span class="error">* <?php echo $payDayErr;?></span>
<br/>
<br/>
<button onclick="myFunction()">Submit</button>
<br/>
<br/>
</form>
In your PHP code, you're checking for $_POST['pay_Period']=='bi_Weekly' when you need to be using the values specified in your radio value field. You have these set to 1 and 2, so you need to use those. That is what will be submitted back to you. See code below
<form method="post" action="">
<p><span class="error">* required field.</span></p>
<p>What is the pay period reported by Company X:</p>
<input type="radio" name="payPeriod" value="1" <?php if (isset($_POST['payPeriod']) && $_POST['payPeriod']=='1') echo ' checked="checked"';?> />Bi-Weekly
<input type="radio" name="payPeriod" value="2" <?php if (isset($_POST['payPeriod']) && $_POST['payPeriod']=='2') echo ' checked="checked"';?> />Semi-Monthly
<span class="error">* <?php echo $payPeriodErr;?></span>
<br/>
<p>What is the clients response to pay period:<br/>
(How often do you get paid, once every two weeks or twice a month?)
</p>
<input type="radio" name="pay_Period" value="1" <?php if (isset($_POST['pay_Period']) && $_POST['pay_Period']=='1') echo ' checked="checked"';?> />Every two weeks
<input type="radio" name="pay_Period" value="2" <?php if (isset($_POST['pay_Period']) && $_POST['pay_Period']=='2') echo ' checked="checked"';?> />Twice a month
<span class="error">* <?php echo $pay_PeriodErr;?></span>
<br/>
<p>Does your pay day result on the same days of the week:<br/>
(i.e.: Every pay checks are paid on Fridays.)
</p>
<input type="radio" name="payDay" value="1" <?php if (isset($_POST['payDay']) && $_POST['payDay']=='1') echo ' checked="checked"';?> />Yes
<input type="radio" name="payDay" value="2" <?php if (isset($_POST['payDay']) && $_POST['payDay']=='2') echo ' checked="checked"';?> />No
<span class="error">* <?php echo $payDayErr;?></span>
<br/>
<br/>
<button onclick="myFunction()">Submit</button>
<br/>
<br/>
</form>
Everything you need to know about radio buttons is right here.
Maybe you will find some other useful information
if you scroll a bit down you will see how you can keep certain radio buttons checked.
goodluck
EDIT:
Missed the javascript, Ill look for a solution for you
A related question was already asked some time ago, it can be found here

Passing data from DB to update form using CI CRUD

I'm trying to write a compact update controller for CRUD activity. Here is the basic code:
Controller:
function update($id)
{
$this->form_validation->set_rules('name','Name','required');
$this->form_validation->set_rules('age','Age','required|is_numeric');
$this->form_validation->set_rules('country','Country','');
$this->form_validation->set_error_delimiters('<br /><span class="error">', '</span>');
if ($this->form_validation->run() == FALSE) {
//Failed validation or first run
$data = $this->my_model->get_record($id);
$this->load->view('myform_view', $data);
} else {
//Validation success, update DB
}
}
View:
<?php
$attributes = array('class' => '', 'id' => '');
echo form_open('my_form', $attributes); ?>
<p>
<label for="name">Name</label>
<?php echo form_error('name'); ?>
<br /><input id="name" type="text" name="name" value="<?php echo set_value('name'); ?>" />
</p>
<p>
<label for="age">Age</label>
<?php echo form_error('age'); ?>
<br /><input id="age" type="text" name="age" value="<?php echo set_value('age'); ?>" />
</p>
<p>
<label for="country">Country</label>
<?php echo form_error('country'); ?>
<br /><input id="country" type="text" name="country" value="<?php echo set_value('country'); ?>" />
</p>
<p>
<?php echo form_submit( 'submit', 'Submit'); ?>
</p>
<?php echo form_close(); ?>
This is the basic structure, however the first time the form is run there is no validated data. Therefore I have to grab this from the DB. Whats the best way to pass this to the view on the first run? And then once the form has been submitted, if validation fails then I want the failed data to show not to reload from the DB again. Whats the best way to do this?
You should have another method for the viewing aspect. Then submit your form against the "update" method. In there, you define the the form_validation as you have now.
I asked a similar question. See this link
grab the data in update controller first for edit such as
$query = $this->db->where('id',$id)->get('table_name');
$data['edit'] = $query->result_array();
and then check it in view file
value="<?php if(isset($edit[0]['age'])){echo $edit[0]['age'];}else{echo set_value('age');}?>"

Simple script issue?

for some reason I cannot get any form to work correctly on my website, I even went to w3school and copied a simple test form to see if it works, and it does not, here it is:
welcome.php:
<?
Welcome <?php echo $_GET["fname"]; ?>!<br />
You are <?php echo $_GET["age"]; ?> years old.
?>
form:
<form action="welcome.php" method="get">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
I'm not sure if it matters or not, but I tried with and without brackets, and still I get a blank page, in explorer I get a 500 Error, most likely causes is maintenance or Programming Error", but I had the same issue last night so I doubt its maintenance, and everything else works.
Remove the beginning <? and ending ?> from your welcome.php.
Your form uses get and you're reading from $_POST.
Either change html to
<form action="welcome.php" method="post">
or change the php to
Welcome <?php echo $_GET["fname"]; ?>!<br />
You are <?php echo $_GET["age"]; ?> years old.
Also, make sure the value is present using the isset
Welcome <?php echo isset($_GET["fname"]) ? $_GET["fname"] : "Guest"; ?>!<br />
When you use $_POST["fname"] you should also specify post as method in your form
welcome.php:
<?
Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years old.
?>
form:
<form action="welcome.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>