Issue in using checkbox in sign up form in Codeigniter - javascript

My sign up form was previously working well. However, I had to add an acceptance page or terms and conditions before sign up can be successful. I thought it would be better to include it in sign up page rather than after sign up (before being presented with member's homepage). Problem is, it's having a lot of issues. It's not working properly.
Here's my code in view page: (i added this at the bottom of all fields before sign up button)
Please proceed only if you accept our <a target="blank" href="<?php site_url("in/terms_and_conditions");?>">terms and conditions</a>.
<input type='checkbox' name='terms' value='checked' id='terms' required autofocus/><br/>
Right now, it seems to work fine (codeigniter built in validation prompts up a message telling the user to click before he can proceed). Issue is 1. the link ("in/terms_and_conditions") does not show properly. Whenever the corresponding text is clicked, instead of showing the proper page, it just opens up a new sign up page.
Second issue is the presence of errors as follows:
Message: Undefined index: c_terms in model Line Number: 24
Line 24 is this:
'terms'=> $post_obj['c_terms']
I tried to add this to my array. Was it actually correct?
The second error shown is:
Column 'terms' cannot be null
INSERT INTO `client` (`first_name`, `last_name`, `email_address`, `password`, `address`, `tagline`, `profile`, `interests`, `billing_mode`, `terms`) VALUES ('dsfhkds', 'hfdskhflk', 'test#yahoo.com', '123456', 'fsdkfhsdk', 'sdkfhsdkf', 'sdklhfslkdhflsdhf', 'kdslhflks', 'Escrow', NULL)
What I did to my original table is I added column which I named "terms", set it to text type and no default value.
Please help me fix this.
Thanks!

Issue 1:
Did you create the page "in/terms_and_conditions" ? make sure?
Controller Name: in
Action Name : terms_and_conditions
Issue 2:
You have named checkbox as "terms". then, you should get the posted value as follows
'terms'=> $post_obj['terms']
Issue 3:
Set "terms" column default value as "NULL"

I see three problems:
You're not echoing the result of the site_url function. Just put echo in front of it.
If $post_obj is your '$_POSTarray you have to use thename` attribute of the HTML input as the key:
'terms' => $post_obj['terms']
Your problem is that you're not setting any text to be saved in terms. Add it to the second parameter of $this->db->insert('table', $data) like this: $data['terms'] = '...'

Related

clearvalidators not working in angular 6 form control

I have two form group names like below. Sometimes one form is not shown to user. When both are shown I have no issues. And I have a button which is visible when the form is valid.
<div
*ngIf="showPersonalInfo"
class="personalInfo"
formGroupName="personalInfo"
>
<div
*ngIf="showFamilyInfo"
class="familyInfo"
formGroupName="familyInfo"
>
<button
*ngIf="InfoForm.valid"
class="submitButton"
</button>
And I initialize my form using below code.
this.InfoForm = this.formBuilder.group({
personalInfo: this.getPersonalInfo(),
familyInfo: this.getFamilyInfo(),
});
The code in this.getFamilyInfo() will set showFamilyInfo to true or false and it initializes the form in both the cases otherwise my html throws familyInfo is not found.
One of our service sometimes looks for the member profile and pulls existing family info/personal info and fills the model and sets showPersonalInfo/showFamilyInfo to true.
when showFamilyInfo is false my InfoForm.FamilyInfo form control is showing as invalid. To avoid this error i am clearring validators using below code but it still shows the familyInfo form control status invalid. My PersonalInfo is valid though.
How can ignore everything related to FmilyInfo when showFamilyInfo is false so the button will be visible.
this.InfoForm.get('familyInfo').clearValidators();
this.InfoForm.get('familyInfo').updateValueAndValidity();
I think you need to clear the errors before you can update the Validity. In the linked post, the answer by Julia P. covers how to clear the errors. Then you run updateValueandValidity. How can I manually set an Angular form field as invalid?
I had the same issue, in my case, the code setErrors(null) solved the problem.
Try to do this:
this.InfoForm.get('familyInfo').clearValidators();
this.InfoForm.get('familyInfo').setErrors(null);
this.InfoForm.get('familyInfo').updateValueAndValidity();

How to see if a form element was not posted

I have a form where e-mail is optional. To control that there is a checkbox. If that checkbox is unchecked, the e-mail textbox would be disabled and therefore not posted on submit. However, on the next page, if I have code like as shown below, it gives me an error if the e-mail textbox is disabled.
if (isset($_POST['submit']))
{
$_SESSION["email"] = $_REQUEST['YourEMail'];
....
}
To get around that problem, I progammatically enable a disabled e-mail textbox just before submitting besides setting its value to an empty string. The code for that is shown below.
document.getElementById('YourEMail').disabled = false
document.getElementById('YourEMail').value = ''
However, one annoying problem remains, which is that, if the user goes back to the original page, the e-mail textbox is enabled, since I enabled it problematically just before submitting the form. However, I want it to be disabled in that case. How, can I achieve that? Alternatively, how in the next page, I could see that e-mail box was disabled and therefore not even try to read $_REQUEST['YourEmail']?
if the field "#YourEMail" is optional you can check if exists in PHP. There is no need for enable/disable the field using JS.
if (isset($_POST['submit']))
{
if (isset($_REQUEST['YourEMail']) && !empty($_REQUEST['YourEMail'])){
$_SESSION["email"] = $_REQUEST['YourEMail'];
}
}
You can test it like this using a ternary:
(isset($_REQUEST['YourEMail']) && !empty($_REQUEST['YourEMail'])) ? $_SESSION["email"] = $_REQUEST['YourEMail'] : FALSE;
This would only set the session variable if the request variable is set.

Dropdown box getting values from mySQL shows blanbk entries

I'm using the template from this mySQL x AJAX tutorial (http://www.9lessons.info/2010/08/dynamic-dependent-select-box-using.html) to create dependent dropdowns.
How the code should work:
Coach selects what activity group ($activity) he wants to browse from box one.
Box two the populates with a list of players($username) who are part of that activity.
It does the above, but the entries show up blank as opposed to printing the name - see screenshot attached. Below is the piece
<?php
if($_POST['activity'])
{
$activity=$_POST['activity'];
$sql=mysql_query("SELECT id AND username FROM player WHERE activity='$activity'");
while($row=mysql_fetch_array($sql))
{
$id=$row['id'];
$username=$row['username'];
$activity=$row['activity'];
echo '<option value="'.$username.'">'.$username.'</option>';
}
}
?>
I've messed around with the number of entries in the db, and the blank values change respectively (when changed to 5 people being in group, 5 blank spaces show, etc.)
It's really odd because of the fact it appears to be working, just not showing the names.
Any ideas?
Cheers.
Try fixing your query. You are ANDing the values id and username
SELECT id, username FROM player WHERE activity='$activity'
You forgot to isset your $_POST['activity'].

Remove further inputs in Joomla k2 submission form and just keep Extra-Fields inputs

I'm going to use Joomla K2 component as a directory system only, So just show Extra-Fields in front-end contents.
Therefore in the K2 item submission form which is available to registered users, I tend to remove all further inputs (including content tab and its huge textarea for writing post, attachment tab, title input, publish radio buttons and so on) and keep extra-fields' inputs only. I tried to do this through k2 template overriding by hiding those inputs using CSS or HTML however it's not a good idea because users are still able to show and see hidden stuff by set display to normal via browsers' developer tools.
Also it isn't possible to achieve this purpose by put those fields in an always false PHP condition since some inputs need to have at least one value, It seems.
Below is the default layout of K2 submission form in user section, Red areas are those I want to make them removed and inactive:
And here's the source of default layout:
com_k2/templates/default/itemform.php
By hiding category input from users, I also need to set a predefined category which all contents that users submit would apply to it and Extra-fields related to that category are shown to users in submission form.
Is there any way to define a value in template overriding files and hide its related field completely? (It's better to be by variable but constant would work too). I would need it to Auto title assignment for item submitted by users too (However it's not as necessary as
other things)
All these change would be in K2 adding item form in front-end site and not Admin section.
What's the workaround to this all?
Regards
I know this question is old but this is my idea, I did something similar, not exactly the same.
Because you can't submit the form if you remove the required fields like Category or Title, you can put a hidden INPUT field with a random value, as long as it is not empty value. In your override file templates/YOUR TEMPLATE/html/com_k2/default/itemform.php instead of showing category selection:
<tr>
<td class="adminK2LeftCol">
<label><?php echo JText::_('K2_CATEGORY'); ?></label>
</td>
<td class="adminK2RightCol">
<?php echo $this->lists['categories']; ?>
</td>
</tr>
You use something like this
<input type="hidden" id="catid" name="catid" value="-1">
Yes naughty users can use Firebug to put their values in that INPUT, but you still can build a plugin and listen to onBeforeK2Save event then set your default value of category to your own value (0, 1 , 2 anything) before saving the content to database. By using this way, you can generate title for your K2 item too.
<?php
defined('_JEXEC') or die ;
JLoader::register('K2Plugin', JPATH_ADMINISTRATOR.'/components/com_k2/lib/k2plugin.php');
class plgK2MyExample extends K2Plugin
{
var $pluginName = 'myexample';
var $pluginNameHumanReadable = 'My Example K2 Plugin';
function onBeforeK2Save(&$item, $isNew)
{
$item->catid = 10000;
$item->title = 'my own title';
}
}
Check the example plugin here: https://github.com/joomlaworks/example-k2-plugin (onBeforeK2Save is missing in the example plugin).
onBeforeK2Save is called in administrator/components/com_k2/models/item.php ("save" function).

jquery cant read textfield value

I got a problem today with some codes regarding reading textfield value.
the value is returned back to the page as the result of a query from a php file:
//the first text filed with event calling a php file to query the name's order in the list.
<label for=name>Name</label>
<input id=name name=name type=text placeholder="Individual / Company Director" required onblur="getOrderInList();" >
the function getOrderInList() does a query and sends the result back to the caller page using javascript
parent.document.getElementById('customerorder')=document.getElementById('query_result');
the query result which is an integer, is supposed to be back to the main page where the name text field is in a specific hidden text box customercode
using jQuery i need to show it on the page using an alert for example. but seems to be undefined.
can anyone help me with this.
your code is in javascript and you are mentioning jquery in your question. its a bit confusing but my guess is you need your javascript code to be corrected
parent.document.getElementById('customerorder').value = document.getElementById('query_result').value;
In JavaScript:
parent.document.getElementById('customerorder').value = document.getElementById('query_result').value;
In jQuery:
$('#customerorder').val( $('#query_result').val() )

Categories