printing in joomla - joomla

I need help to solve a printing problem completely blocking my project. To be precise and clear, I have two articles Joomla containing PHP code (I use the pluging Free sourcerer).
The first article contains the following code:
{source}
<form method="post" action="http://localhost/essai/index.php?option=com_content&view=article&id=2">
<p>
<input type="text" name="num" />
</p>
<input type="submit" value="Display the value of num" />
</form>
{/source}
The second article whose id is 2 contains the following code:
{sourcer}
if (isset ($_POST [ 'num'])) {
$Address=J Request :: getVar( 'num', '', 'post');
echo $Address;
} else {
echo "num does not exist";
}
{/source}
My objective is recover the value of the input field of the form num in the second article with id 2 and print. When I click on the button "Display the value of num" value zone num is retrieved and displayed, but when I click on the link to print
the article, "Does not exist num" is displayed in the open windows.
When I print the article, $ _POST ['num'] does not exist!
Is that this is a problem printing in Joomla or other? Help me please.
NB: I use Joomla_2.5.9, Template Beez2 integrated in joomla,
Sourcerer-Free v4.1.3

There are 2 changes you need to make in order to get this to work.
1 - I have included the form inside the PHP
{source}
<?php
echo'<form method="post" action="http://localhost/essai/index.php?option=com_content&view=article&id=2">' .
'<p>' .
'<input type="text" name="num" />' .
'</p>' .
'<input type="submit" value="Display the value of num" />' .
'</form>';
?>
{/source}
2 - Remove some of the extra SPACES from the code
{source}
<?php
if (isset($_POST['num'])) {
$Address=JRequest :: getVar('num','','post');
echo $Address;
} else {
echo "num does not exist";
}
?>
{/source}

Related

File upload with multiple browse button (populated from array) on Laravel

I need to upload file from dynamic upload button that generated form array as below code (Edited and workd already).
#foreach( $transfer as $key => $item )
<tr>
<td>
<input type="file" name="document[]" class="doc filestyle"/>
</td>
</tr>
#endforeach
This is boostrap filestyle
<script type="text/javascript">
$('.doc').filestyle({
buttonName : 'btn-success',
input: false,
icon: false,
});
It only work for single file. But I have no idea for multiple. (Edited and workd already)
if(count(Request::file('document', [])) > 0){
foreach( Request::file('document', []) as $key => $item ){
echo 'Reg ID: ' . $key . '<br />';
echo 'Value: ' . $item->getClientOriginalName() . '<br />';
}
}
Thanks for all advise.
Thats because you are not defining your control name as array
Change This to
<input type="file" name="document" id="doc{{$key}}" class="filestyle"/>
This
<input type="file" name="document[]" id="doc{{$key}}" class="filestyle"/>
Not name="document" change to name="document[]"
and sorry i have missed multiple Attributes in tag thanks to #Md.Sukel Ali
This Might Work
You need to add multiple attribute in your in input field.
<input type="file" name="document[]" id="doc{{$key}}" class="filestyle" multiple="" />

Passing checkbox value from view to controller

How to pass checkbox value from views to controller so that I can compare the checked/unchecked values (for database update)?
Views:
#foreach ($second as $sec)
<br>
<div class = "form-group">
{{$sec->Roll }}
&nbsp&nbsp&nbsp&nbsp
{{ $sec->Name}}
</div>
<div class = "form-group">
<input tabindex="1" type="checkbox" value="{{$sec->Roll}}" name="1" />
</div>
#endforeach
Controller:
foreach ($columns as $col) {
//dd("Y");
if($col == $txt[1]) {
$got=DB::table($req)->select($col)->get();
//dd($got);
//COMPARE CHECKBOX VALUE "CHECKED/UNCHECKED" WITH ITS DEFAULT VALUE
DB::statement("UPDATE " . $req . " set " . $got . " to " . $got . " + 1 WHERE" .$req->Roll . " IN ".( implode(',', $req)));
}
}
Ps: This might be applicable only if my description matches what you are trying to do, because your question seems so.
One of the ways I have done it is not to put any value in the checkbox element. Then inspect if the value returned is string with is_string($the_variable) or not. That is, instead of:
<input tabindex="1" type="checkbox" value="{{$sec->Roll}}" name="checkbox_1" />
I'll have:
<input tabindex="1" type="checkbox" name="checkbox_1" />
This might not be an ideal solution, but a bit curious if you have tried it.
So in the controller, any checked checkbox would have 'on' as the value, while unchecked one would have null:
so if I do in my controller:
return request()->all();
I should get the values of the checked as 'on' and the values of the unchecked as null
So i'll do for example in controller:
if(is_string(request()->get('checkbox_1))) {
//checked
else {
// unchecked
}
Hope this is clear now.
Just for an update:
One other way to do this is to pass the key of the column you are trying to update when making the foreach, so you will have something like this:
#foreach ($second as $key=> $sec)
then on the checkbox it will serve as different names:
<input tabindex="1" type="checkbox" name="{{ $key }}" />
This way if you do return request()->all(); at the first in your controller, you can then tell if something else is wrong or not.
Please make sure you note the $key in that foreach() so to be sure you are doing the right thing.

form submit in codeigniter going to blank page

I am submitting form using form helpers and it's going to blank page and when I see the view source, the action in the view source is like this http://::1/ci1/login_validation I don't understand the ::1 in it shouldn't it be localhost:8080/? But if I use simple form tags like regular html it works fine?
<?php
echo form_open ('login_validation');
echo form_input('email');
echo form_password('password');
echo form_submit('login_submit', 'login');
echo form_close();
?>
View Source
<form action="http://::1/ci1/login_validation" method="post" accept-charset="utf-8">
<p>Email:<input type="text" name="email" value="" /></p>
<p>Password:<input type="password" name="password" value="" /></p>
<p><input type="submit" name="login_submit" value="login" /></p>
</form>
I would think it is a couple of thing like.
If your form action has http://::1/ then does not submit correct because base url is empty
$config['base_url'] = '';
Fill base url example:
$config['base_url'] = 'http://localhost/project_name/';
On codeigniter 3 version not best idea to leave it blank because you will run in to that issue.
Make sure your class and file names of controllers etc have first letter upper case.
Filename: Login_validation.php
Controller:
<?php
class Login_validation extends CI_Controller {
public function index() {
// form submit controller code.
}
}
View
<?php
echo form_open ('login_validation');
echo form_input('email');
echo form_password('password');
echo form_submit('login_submit', 'login');
echo form_close();
?>
This is a common mistake people for get to check.
Why http://::1/??
This mean your base_url() is empty.
Then how this http://::1/ comes??
When your project URL is empty, CI detect your project URL. So this http://::1/ knows your project path.
How to set base_url()??
In config/config.php set $config['base_url'] = ''; the project URL.
Keeping base_url() empty any harm??
When you in local its ok and fine. But when you host that just add your site URL to it.
$config['base_url'] = 'www.stackoverflow.com';

Cannot get the data in another page in CI

I have form and when i submit that data are passed to next page i can see that in url. but i when i get and print that it shows nothing , here i have attached my coding
<form action="addfilters/add"><input type="hidden" name="id" value=<?php echo $filters->id ?> > <input type="submit" value="Add New"></form>
my controller
<?php
class AddFilters extends Admin_Controller
{
function add(){
echo $this->input->post('id');
}
}
URL
http://localhost/code/index.php/admin/addfilters/add?id=1
but when i print ,it shows nothing , please help me
i have just used
<?php echo form_open_multipart('admin/addfilters/add'); ?>
top of the form. it works fine :-)

Adding a 'add another' option in Wordpress custom meta box using jquery $.post

I'm creating a wordpress plugin, with a custom post type and in that post type a custom meta box.
Inside the meta box, I have a form that let's the user input: Date, Media, Title.
The form looks like this:
$mc_date = get_post_meta($_GET['post'],'mc_date',true);
$mc_media = get_post_meta($_GET['post'],'mc_media',true);
$mc_title = get_post_meta($_GET['post'],'mc_title',true);
echo '<form id="add_media_form">';
echo '<table>';
echo '<tr>';
echo '<td>Date</td><td>Media</td><td>Title</td>';
echo '</tr>';
echo '<tr>';
echo '<td><input type="text" name="mc_date" value="'.$mc_date.'" class="datepicker"/></td>';
echo '<td><input type="text" name="mc_media" value="'.$mc_media.'" /></td>';
echo '<td><input type="text" name="mc_title" value="'.$mc_title.'" /></td>';
echo '<td><img src="'.WP_PLUGIN_URL.'/mc/plus.png" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '<div class="addmedianotify"></div>';
jquery:
jQuery('.add_new_media').click(function(e){
var plug = jQuery(this).attr('rel');
e.preventDefault();
jQuery.post(plug + '/ajax_add_media.php',jQuery('#add_media_form').serialize(),function(data){
jQuery('.addmedianotify').html('<span>'+data+'</span>');
});
});
What I want to do, is that when the user click the 'add_new_media' link/image a new set of textboxes for date, media and title will appear.
My main concern is that, what's the trick to name those inputs which is dynamic. and to save and retrieves the custom data in it.
Because the page will still update when the user clicks 'Update' you would need to be able to save your fields on save_post and in your ajax. Using ajax for this might not be the best method as you're making more work for yourself by needing to save that data twice. I would ditch the ajax and simply use an html array so you can add on fields and make one submission when the user clicks 'Update'. To add new rows as the user needs, I would simply clone your tr and append it to the table in your click event. Something like...
The PHP & HTML
<img src="'.WP_PLUGIN_URL.'/mc/plus.png" />
<table>
<tr>
<td>Date</td>
<td>Media</td>
<td>Title</td>
<td></td>
</tr>
<?php
//$mcs will be a multi-dimensional array with this method
$mcs = get_post_meta($post->ID,'mcs',true);
//Loop through each set of saved mc data (date, media, and title per item) and output inputs so the saved values can be edited and resaved.
foreach ($mcs as $mc) : ?>
<tr>
<td><input type="text" name="mc[][date]" value="<?php echo $mc['date'] ?>" class="datepicker"/></td>
<td><input type="text" name="mc[][media]" value="<?php echo $mc['media'] ?>" /></td>
<td><input type="text" name="mc[][title]" value="<?php echo $mc['title'] ?>" /></td>
<td>Remove</td>
</tr>
<?php endforeach ?>
</table>
The Javascript
<script>
(function($){
//Grab the first
$('.add_new_media').click(function(e) {
//Use the first tr as a cookiecutter and add another cookie to the bowl :)
$('table tr:first-child')
.clone()
.appendTo($('table'))
.find('input')
.val('')
}
$('.remove').click(function(){
$(this).parent().parent().remove()
})
})(jQuery)
</script>
The PHP upon form submission
<?php
if ($_POST) :
//$_POST['mc'] is a multi-dimensional array of all the date/media/title input rows
print_r($_POST['mc']);
/*
..would look something like
Array (
[0] => Array (
'date' => 'some value',
'media' => 'some value',
'title' => 'some value'
),
[1] => Array ( ... ),
[2] => Array ( ... ) ... and so on
)
*/
//RUN INPUT VALIDATION!!
//Update the list
update_post_meta($post->ID, 'mcs', $_POST['mc']);
endif;
?>

Resources