Get value from dropdown after submit in codeigniter - codeigniter

I have dropdown list with some universities and in case the user is in a university that isn't in the list he can add it with an input box. My issue is that after the user clicks the submit button I can't get the value from the dropdown.
My code in the view is:
echo "University:";
?>
<div id="university2" style="display:block;">
<?php
echo form_dropdown('university2',$this->session->userdata('user'));
echo "&nbsp";
echo "<a href= javascript:ShowContentuni('university')>Other</a>";
?>
</div>
<div id="university" style="display:none;">
<?php
echo form_input('university',$this->input->post('university'));?>
</div>
And my code in the controller is:
if(isset($_POST['university']))$university= $this->input->post['university'];
else if(isset($_POST['university2']))$university=$this->input->post('university2');
Any ideas what I'm doing wrong??

It looks like there are two problems:
always overriding the value of $university with the post value of 'university2', even if it is empty
the form has two inputs called university, only the second one is being referred to
A quick fix would be to first delete the second 'university' form element, i.e. delete this:
echo form_input('university',$this->input->post('university'));
Then check that the user if the user has manually entered a university name, and use that if so. If the user did not enter a university name, use whatever the dropdown value is. The code would look like this:
$universityFromDropdown = $this->input->post('university');
$universityFromManualInput = $this->input->post('university2');
$university = is_string($universityFromManualInput)
&& strlen($universityFromManualInput) > 1
? $universityFromManualInput : $universityFromDropdown;

Related

How to select by non-direct child condition in Xpath?

I would like to show an example.
This how the page looks:
<a class="aclass">
<div class="divclass"></div>
<div id="innerclass">
<span class="spanclass">Hello</span>
</div>
</a>
<a class="aclass">
<div class="divclass"></div>
<div id="innerclass">
<span class="spanclass">Pick Delivery Location</span>
</div>
</a>
I want to select anchor tags that have a child (direct or non-direct) span that has the text 'Hello'.
Right now, I do something like this:
//a[#class='aclass'][div/span[text() = 'Hello']]
I want to be able to select without having to select direct children (div in this case), like this:
//a[#class='aclass'][//span[text() = 'Hello']]
However, the second one finds all the anchor tags with the class 'aclass' rather than the one with the span with 'Hello' text.
I hope I worded my question clearly. Please feel free to edit if necessary.
In your attempt, // goes back to the root of the document - effectively you are saying "Give me the as for which there is a span anywhere in the document", which is why you get them all.
What you need is the descendant axis :
//a[#class='aclass' and descendant::span[text() = 'Hello']]
Note I have joined the conditions with and, but two separate conditions would also work.

Using XPath to get complete text of paragraph with span inside

<ul>
<li class="xyz">
<div class="divClass">
<span class="ContentItem---status---dL0iS">
<span>Success</span>
</span>
<p class="ContentItem---title---37IqA">
<span>Test Check</span>
: Please display the text
</p>
</div>
</li>
<li class="xyz">
<div class="divClass">
<span class="ContentItem---status---dL0iS">
<span>Not COMPLETED</span>
</span>
<p class="ContentItem---title---37IqA">
<span>Knowledge</span> A Team
</p>
</div>
</li>
.... and so on
</ul>
This is my html structure.I have this text Test Check inside a Span and : Please display the text inside a Paragraph tag.
What i need is ,i need to identify, whether my structure contains this complete text or not Test Check: Please display the text.
I have tried multiple ways and couldn't identify the complete path.Please find the way which i have tried
//span[text()='Test Check']/p[text()=': Please display the text']
Can you please provide me the xpath for this?
I think there is one possible solution to identify within the given html text and retrieve. I hope this solves your problem.
def get_tag_if_present(html_text):
soup_obj = BeautifulSoup(html_text,"html.parser")
test_check = soup_obj.find_all(text = re.compile(r"Test Check"))
result_val = "NOT FOUND"
if test_check:
for each_value in test_check:
parent_tag_span = each_value.parent
if parent_tag_span.name == "span":
parent_p_tag = parent_tag_span.parent
if parent_p_tag.name == "p" and "Please display the text" in parent_p_tag.get_text():
result_val = parent_p_tag
break
return result_val
The returned result_val will have the tag corresponding to the p tag element with the parameter. It would return NOT FOUND, if no such element exists.
I've taken this with the assumption that the corresponding data entries would exist in a "p" tag and "span" tag respectively , feel free to remove the said conditions for all identifications of the text in the given html text.

How to get Joomla Tag list in a module

I am using Joomla 3.4.8 and it's Article - Latest Module. That module showed only latest article's title but I want to show introtext and tags also.
I was able to show the introtext but didn't able to show tags. Can anyone help me to figure it out? Here is my code given below.
<pre><code>foreach($list as $item):
echo $item->title;
echo $item->introText;
echo $item->tags->itemTag;
endforeach;</code></pre>
When I run this code get the error message:
Notice: Array to string conversion in F:\xampp\htdocs\rnd\joomla\tx_quicx\modules\mod_articles_latest\tmpl\default.php
on line 37
Which corresponds to echo $item->tags->itemTag;
Thanks in advance.
The tags field is an array.
You have to reference the element number you want from that field and then reference its itemTag.
foreach($list as $item):
echo $item->title;
echo $item->introText;
echo $item->tags[0]->itemTag;
endforeach;
Will get the first (0th) item tag. If you want all item tags for all items, you'll have to iterate through all elements of the tags array.
This code solve my issue.
foreach($list as $item){
echo $item->title;
echo $item->introText;
foreach($item->tags->itemTags as $tag){
echo $tag->title;
}
}
Thanks Brandon

Web2py URL callback hidden when clicked and loading ajax

I have been developing an application using web2py. I have a page with a callback link which sends information to another function, this loads the results via ajax in the right sidebar of the page. When the link is clicked, the link itself disappears but the results are loaded correctly. I have to refresh the page for the links to come back. I have been looking at this for ages but can't figure it out, I am relatively new to web2py so probably missed something obvious.
Here is some code:
The view (With the link):
{{if hosts == "Please select a category":}}
{{response.write("Please select a category")}}
{{else:}}
<ol>
{{for i in hosts:}}
<li>{{=A(i['HostName'], callback=URL('selection','getResults.load', vars=dict(clicked=i['HostName'])), target="monitoredDevice")}}</li>
{{pass}}
</ol>
{{pass}}
{{end}}
{{block right_sidebar}}
<div id="monitoredDevice">
</div>
{{end}}
The controller action:
def getResults():
hostName = request.vars.clicked
# hostName = request.vars.hostNameSelected
print(hostName)
try:
task_status = scheduler.task_status(db.scheduler_task.task_name==hostName, output=True)
result = task_status.result
# create_compare_graph()
except(AttributeError): # Error is because there is no scheduler and therefore no status, need to set the values to 0
result = emptyTaskStatusResultsToZero()
try:
return dict(result)
except(TypeError): # There is a task scheduled however there is no run data as it has not been run before. Causes an error.
return emptyTaskStatusResultsToZero()
I think there is something wrong with the =A link in the view?
Thank you!
The method just prevents the view from getting an error if nothing is returned so I set all the values to zero so the view has something to render.
def emptyTaskStatusResultsToZero():
return {'percent_diff_in': 0, 'percent_diff_out':0, 'now_avg_30mins_in': 0
, 'now_avg_30mins_out':0, 'prev_week_avg_30mins_in':0, 'prev_week_avg_30mins_out':0,
'percent_more':0,'percent_less':0, 'count':0}

Problems Saving Large Number of Attribute Option Labels in Magento

I'm running into a problem in a Magento system where saving a large number of attributes either doesn't work at all, or only partially works. It appears to be a javascript related issue, and I was hoping someone on Stack Overflow had some "known science" for dealing with this situation, or could point me in the right direction.
The basic problem is, the Magento system in question has over 250 color attribute option labels. If an admin user attempts to manage these by doing the following
Navigating to Catalog -> Attributes -> Manage Attributes
Selecting the color attributes
Clicking on the Manage Label/Options tab
Editing the last Label Option
Clicking "Save and Continue Edit"
One of two things happens.
In Google Chrome on OS X, the button sticks in the "depressed" state, and after a period of time Google Chrome's "This page is not responsive" kill dialog comes up.
In a mozilla based browser on OS X, clicking the button makes the browser "think" for a bit, but it eventually submits the form. However, only a partial list of attribute labels is posted to the admin controller. This means the user can only edit the first 75 - 100 labels, since the other labels are never submitted.
I have reports from windows users describing the second behavior as well (browsers are non-specific)
The obvious answers are to either investigate the poorly performing javascript, or (Grouch Marx style) "don't do that". Before I spend the time profiling/excavating the javascript on that page, I was hoping there was some known fix for this, or specific knowledge as to what was causing the problem.
Magento CE 1.7.x, if it maters.
Update: The Javascript performance issues are a red herring. They're caused by the massive number of input fields being iterated through in
js/prototype/validation.js
Specifically in this try catch block
try {
if(this.options.stopOnFirst) {
result = Form.getElements(this.form).all(function(elm) {
if (elm.hasClassName('local-validation') && !this.isElementInForm(elm, this.form)) {
return true;
}
return Validation.validate(elm,{useTitle : useTitles, onElementValidate : callback});
}, this);
} else {
result = Form.getElements(this.form).collect(function(elm) {
if (elm.hasClassName('local-validation') && !this.isElementInForm(elm, this.form)) {
return true;
}
return Validation.validate(elm,{useTitle : useTitles, onElementValidate : callback});
}, this).all();
}
} catch (e) {
}
However, even if I short circuit this and have the function return true, the behavior of not saving all the labels persists.
You can try the variable max_input_vars (introduced in PHP 5.3.9), by default it's 1000 so that should be enough, but maybe your configuration uses a lower amount. But I imagine the form just doesn't get through due to the major performance issues you're experiencing.
About the option labels: do they by any change have an uploader for an attribute-image? We had the exact same problem when we installed the GoMage Advanced Navigation extension on a shop with over 300 manufacturer options (the extension uses Magento's built-in Flash-uploader).
We didn't have the extension for that feature so I disabled the uploader, but the extreme performance decrease was definitely in the 300 Flash-movies being loaded. Maybe you can try lazyloading the uploader on a per-option basis by inserting a button or link instead of the movie.
Hope this points you in the right (or exact) direction.
[Working SOLUTION]
Hello as Alan Storm mentioned, this ussue is related with the JS logic, that handles the validation of the option label inputs. I had this problem on a project of one of my clents and I wrote simple extension, that solves it.
You can dowload the exntesion for here: https://github.com/Jarlssen/Jarlssen_FasterAttributeOptionEdit
Basically the extension replaces the original option template with mine template. In my template I rewrote most of the JS in the bottom of the template and replaced the form inputs with div elements ( pseudo inputs ), so when the administrator click on the pseudo input, then its replaced with the real input. In this way we avoid validating all the inputs and we validate only edited and the new added entries. The extension works well if you add options on chunks, for example 500 entries per attribute save.
Hope, that helps.
Additional information: http://www.jarlssen.de/blog/2014/05/07/magento-timeout-saving-attribute-options-type-multiple-select-and-dropdown
Quick look at the pseudo generation code:
<tr class="option-row">
<?php foreach ($this->getStores() as $_store): ?>
<td>
<div class="replace-content pseudo-input input-text <?php if($_store->getId()==0): ?> required-option<?php endif; ?>" id="option[value][<?php echo $_value->getId() ?>][<?php echo $_store->getId() ?>]"><?php echo $_value->getData('store' . $_store->getId()) ?></div>
</td>
<?php endforeach; ?>
<td>
<div class="replace-content pseudo-input" id="option[order][<?php echo $_value->getId() ?>]"><?php echo $_value->getSortOrder() ?></div>
</td>
<td class="a-center default-checkbox">
<div id="option_<?php echo $_value->getId() ?>" class="checkbox-radio-container replace-content">
<?php if($_value->getChecked()) : ?>
<input class="input-radio" type="<?php echo $defaultChooserInputType; ?>" name="default[]" value="<?php echo $_value->getId() ?>" checked <?php if ($this->getReadOnly()):?> disabled="disabled"<?php endif;?>/>
<?php else : ?>
<?php if('radio' == $defaultChooserInputType) : ?>
<span class="fake-radio"></span>
<?php else : ?>
<span class="fake-checkbox"></span>
<?php endif; ?>
<?php endif; ?>
</div>
</td>
<td class="a-left actions-column" id="delete_button_container_<?php echo $_value->getId() ?>">
<div id="option[delete][<?php echo $_value->getId() ?>]" title="<?php echo $this->__('Delete') ?>" class="scalable left pseudo-delete-option">
<span class="pseudo-delete-button" option_id="<?php echo $_value->getId(); ?>">
<span>
<span><?php echo $this->__('Delete') ?></span>
</span>
</span>
</div>
</td>
</tr>
I had exactly this problem (POST truncated) and it comes from a suhosin patch that has a too little POST limit. (or the standard PHP post_max_size)
In your php.ini check these values and increase their values if needed (and restart apache) :
post_max_size
suhosin.post.max_vars
suhosin.request.max_vars
For your second probleme (JS performance issue), I can't help you
Sorry!!
I went through this same problem , solution follows below.
Explanation of the problem
problem
A customer has a very large base of tires that also have many cars added to the same , thereby to migrate moorings between tires and vehicles only 255 characters of the attributes of ids were inserted into the table with it causing error in the migration.
The magento inserts a string with ids separated by ,
The problem occurred in the table "catalog_product_entity_varchar" in the value field which by default is 255 characters if I put text and resolved .
Note : I know you modify the DB is not nice but unfortunately had to perform this operation.
Example product
Tire 175 / 65R14
-> Make ( + - 200 options)
-> Model (+ - 4mil options)
-> Series (+ - 15mil options)
-> Year
-> ...
att,
Same problem here. I solved with BELVG module "Attribute Pagination" : http://blog.belvg.com/attribute-admin-page-pagination-in-magento.html
It works properly.
Hope that helps.
Open your server's php.ini, search for max_input_vars and set its value to greater than 2500 will solve your problem
; How many GET/POST/COOKIE input variables may be accepted
max_input_vars = 5000

Resources