update a form and not load or reload page - php

I have a simple command:
<?php echo form_open("sales/add",array('id'=>'add_item_form')); ?>
How can I make this command so it just updates the form, without reload or redirection. I dont even need to see the form. I have tried all sorts of methods, but wondering if there is something simple here I am missing. I just need to post the data.
This is what is outputted by codeigniter.
<form action="http://127.0.0.1/index.php/sales/add" method="post" id="add_item_form">
<label id="item_label" for="item">
</form>
I have tried jquery but still does not work. Any help would be greatly appreciated.

You could use iframes or xml http requests (ajax)

You absolutely need jquery ajax function to do that. Maybe you have tried different jquery function. Check this out:
http://api.jquery.com/jQuery.post/
There are some examples in that link you can look at.

Do you know the path of your controller? Then you can use jQuery to do that. Check this plugin: http://jquery.malsup.com/form/

Related

Pass value to script without x=something [duplicate]

I am working on a project where i need to access clean URL's always i.e no parameters can be passed in the URL for getting values on another page.
Can anyone please suggest an alternative other than 'Form Submit' method.
Thanks In Advance.
Use $_SESSION for this purpose.
Using $_SESSION you can use variable in multiple pages wherever you want.
// assigning variable
$_SESSION['name']="variable";
//retrieving
echo $_SESSION['name'];
write session_start() at the top of page wherever you want $_SESSION variable
For Clean URL's i prefer you may use HTTP POST Method. Hope that helps.
<form name="frmApp" method="POST" action="/action.php">
</form>
Else, you can use AJAX with jQuery to submit the values to another page.
$.ajax({url:"action.php",success:function(result){
$("div").html(result);
}});
Check out w3schools to get started with AJAX : http://www.w3schools.com/jquery/jquery_ajax.asp
No support for SESSION since i don't like writing php code inside my web page.
Sessions can help, or ajax call.
for using clean url you can use post method in form
<form name='' method='POST' action=''>
You can try mapping resources to the url.
Suppose you want to get mailing address of a customer then you can write.
http://[baseurl]/[customerId]/mailingaddress.
Read more here

submit form after correct reply from post

index.php:
$.post('example.php',{ id:pin },
function(data) {$("#test").html(data);}
<div id='test'></div>
<form><input...></form>
Using the above i'd hoped to drop a script into example.php page that would cause the page to submit...
example.php:
if($_post['id']==5){
echo '<script>function submitform(){document.getElementById("form").submit();}
</script>';i}
I had planned to add a DOM even listener for mouse movement key press... and then have that fire off the submitform() script... I tried a few things without luck and I know there has to be a cleaner/Working way...
Thanks,
JT
The problem is you're not calling your submitform() function, but since you want to run the code right away I think it's better if you don't use the function at all and just output the code. Also make sure the form has the id attribute.
So if I understood correctly you want to submit a form after having submitted data already?
If so why don't you just submit everything and process it server side only if conditions are met?

Codeigniter PHP - loading a view at an anchor point

I have a form at the bottom of a long page, if a user fills out the form but it doesn't validate the page is reloaded in the typical codeigniter fashion:
$this->load->view('template',$data);
however because the form is way down at the bottom of the page I need the page to load down there like you do with HTML anchors. Does anyone know how to do this in codeigniter?
I can't use the codeigniter
redirect();
function because it loses the object and the validation errors are gone. Other frameworks I've used like Yii you can call the redirect function like:
$this->redirect();
which solves the problem because you keep the object. I've tried using:
$this->index()
within the controller which works fine as a redirect but the validation errors are in another method which is where the current page is loaded from:
$this->item($labs)
but when I use this it get stuck in a loop
Any ideas? I've seen this question a lot on the net but no clear answers. I'm researching using codeigniter "flash data" but think it's a bit overkill.
cheers.
I can't personally vouch for this, but according to this thread if you append the anchor to the form's action, it will work.
CodeIgniter helper:
<?php echo form_open('controller/function#anchor'); ?>
Or vanilla HTML:
<form method='post' action='controller/function#anchor'>
If you were open to using Javascript, you could easily detect a $validation_failed variable and appropriately scroll. Or, even better, use AJAX.
Another option is to put the form near the top of the page?
Ok, as far as I understood your problem, it isn't much related to the back end(codeigniter). You want the form at the bottom of the page to be 'what-users-sees-on-page-load' (since you mention anchors).
Now, what you can do is, you can set delimiters for your validation error messages using:
echo validation_errors('<div id="bottom_form_error">', '</div>');
Using jQuery ScrollTo, do:
$( function() { $('#bottom_form_error').ScrollTo(); } );
And, the user will be scrolled to the errors at the bottom of the page. Don't forget to include jQuery too.
Anchor hash fragment click is different - it is scrolling at ∞ speed.
I hope that is what you wanted.
P.S. I am ignoring what you said below this line:
Does anyone know how to do this in codeigniter?
as I felt it is not really relevant to the question.

Pass values from one page to another without form and without passing in URL

I am working on a project where i need to access clean URL's always i.e no parameters can be passed in the URL for getting values on another page.
Can anyone please suggest an alternative other than 'Form Submit' method.
Thanks In Advance.
Use $_SESSION for this purpose.
Using $_SESSION you can use variable in multiple pages wherever you want.
// assigning variable
$_SESSION['name']="variable";
//retrieving
echo $_SESSION['name'];
write session_start() at the top of page wherever you want $_SESSION variable
For Clean URL's i prefer you may use HTTP POST Method. Hope that helps.
<form name="frmApp" method="POST" action="/action.php">
</form>
Else, you can use AJAX with jQuery to submit the values to another page.
$.ajax({url:"action.php",success:function(result){
$("div").html(result);
}});
Check out w3schools to get started with AJAX : http://www.w3schools.com/jquery/jquery_ajax.asp
No support for SESSION since i don't like writing php code inside my web page.
Sessions can help, or ajax call.
for using clean url you can use post method in form
<form name='' method='POST' action=''>
You can try mapping resources to the url.
Suppose you want to get mailing address of a customer then you can write.
http://[baseurl]/[customerId]/mailingaddress.
Read more here

Getting source code from page AFTER jQuery function in PHP

I'm trying to get the source code from this page, to get the code of the timetables, and then parse it.
But when I fetch it with file_get_contents, the div I'm looking for is empty. I searched in the code, and it looks like it's filled with jQuery when to body is loaded.
So my question is : how can I get the source code of the page after the jQuery is executed ?
Thanks.
Since jQuery is javascript, php's file_get_contents will not help because it does not execute javascript.
Either find out which ajax data they load and use them directly, or use a browser ;)
the information you want comes from this page http://www.cinesion.ch/cinesion/timetable.php through an AJAX request so file_get_contents will never get it unless you do the call directly to this page...
try this one
http://www.cinesion.ch/cinesion/timetable.php?date=%&movie=%&city=%&_JEXEC=1

Categories