Link to home
Start Free TrialLog in
Avatar of Nura111
Nura111

asked on

how to go back to the same page "status" when using forms in php in just part of the page?


HI all an issue im having:

I have a pop up form that is reside in generate.php
the form is "called from the main application page main.php
(generate.php is actully eching the result inot the page (between others also the pop up form)

the handel of the sumbit action is in the main.php
if (isset($_POST['spamIt'])){
update db
other
}

my problem: after sumbitiing the form the the web page that will show is main.php part I want it to sho the same page that was before sumbitiing the form.
any ideas?


I think in general I have a problem to understand the server loading of the diffrent page and what is happening when sumbitiing form using javascript/ajax and etc
Thank you
<form id = "popup_form_{$row['id']}" method ="post" style="background-color:white; border:2px solid blue;padding:4px; width:250px; position:absolute">

			<input type="hidden" name="id" value ="{$row['id']}">

			<input type="hidden" name ="email" value ="{$row['email_address']}">

			<input type="submit" value="SpamIt" name="spamIt" style="margin-right:15px">

			<input type="button" value="Close" onclick="closePopup()"/>

Open in new window

Avatar of user_n
user_n
Flag of United States of America image

When a form is submitted it is sent an GET or POST HTTP request to the server. In form "action" parameter shows what script will processed the request.

 http://www.tizag.com/phpT/postget.php
http://www.w3schools.com/php/php_post.asp
Avatar of Nura111
Nura111

ASKER

yes you can see in the form code its using method post and main.php hande that but how to I "save" the same screenshot  of the page (that was showing info also from generate.php)  and after handeling the form to show the same page as before
http://dkellner.hu/example018.php

The trick is to submit into a hidden IFRAME - your server side script will get all the things submitted but no visible changes will happen on the user side.

 
<?php

if(!$_POST) {
	?>
	<iframe name="scon" style="display:none"></iframe>
	<form target="scon" method="post">

		Whatever 1: <input type="text" name="whatever1" value="Hello"><br>
		Whatever 2: <input type="text" name="whatever2" value="World"><br>
		<br>

		<input type="submit">


	</form>
	<?
	exit;
}


?>
<script type='text/javascript'>

	var G=<?=json_encode($_POST)?>;

	alert(
		"1: "+G.whatever1+"\n"+
		"2: "+G.whatever2+"\n"+
		"We can save them now, without disturbing the form itself!"
	);


</script>

Open in new window

you can add <input type="hidden" element and to place in it the url from which the request was made
http://www.w3schools.com/tags/att_input_type.asp
Avatar of Nura111

ASKER

user_n:   is there any attribute for that I can add?
for exmp: like this but for the page im in right now?
You can add something like

<INPUT TYPE=hidden URL="temp.php">
temp.com to be the page that you want to go back
than in the page where you should process the form you can use something like
include 'temp.php';
Avatar of Nura111

ASKER

dkellner:: im sorry I dont get you exmples and how to implement it in my code.

You have something like this in your code already

<input type="hidden" name ="email" value ="{$row['email_address']}">
Avatar of Nura111

ASKER

user_n: I understand what I need to add to the form I dont understand how to move to this url form the next part

(isset($_POST['spamIt'])){
update db
other
}
Avatar of Nura111

ASKER

doesnt I need to use javascript or ajax for that to change just part of the page?
ASKER CERTIFIED SOLUTION
Avatar of user_n
user_n
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nura111

ASKER

" There you can change the page and return the result of the changes to the user"

how can I return a diffrent page thatn the page the form is process in in my code the form is processes in main.php ans I want to return generate.php
http://www.w3schools.com/TAGS/tag_form.asp
action       URL       Specifies where to send the form-data when a form is submitted       STF

in this url will be your php page that will process the changes

http://www.tizag.com/phpT/examples/formex.php
Avatar of Nura111

ASKER

I will try to explain it again:
 I want the action to be main.php  I dont need to write that the code I attched to the question worked because its techincally caliing from main.php that was loading genreate.php that echo the from on part of the page)

but I want after sumbitiing the form to do something in the (isset($_POST['spamIt'])){
update db
other
}  
that will make the changes in the page but show the part of the page that wasnt change the same.
and not to reload whoole of main.php again

is it it possible? or I need to do it in a diffrent way?
Avatar of Nura111

ASKER

how can I use your former suggestion:
You can add something like

<INPUT TYPE=hidden URL="temp.php">
temp.com to be the page that you want to go back
than in the page where you should process the form you can use something like
include 'temp.php';

How can I redirect it to the temp.php in the code?
Nura111: my example is about submitting a form without going to another page.
What I understood from your original question is you need a way to do a POST but stay on the page while you do.

Is this the question, or have I completely misunderstood it?
I don't understand exactly what you want.

there are two strategies to change a site
1. To do it on the serverside - like php, asp, java server pages
this  is done with forms. When a form is submited the data in input fields through post or get method are sent to the server to the page described in action parameter of the form. In this page through get or post you can get data and change the site you want to send to the user. http://www.tizag.com/phpT/postget.php The site that is sent to the user is that described in action parameter. You can use include redirect php functions to include another php site.
2. To do it on the local machine - i only know javascript for this. W3school is a good place to learn javascript. In internet there are many example

Ajax - I don't know nothing about it
Avatar of Nura111

ASKER

user_n:
1. if no action is mentioned ? which script will get back the data from the server?
"You can use include redirect php functions to include another php site."- how do I do it in my exmple ? I dont understand it"


Avatar of Nura111

ASKER

dkellner: I dont know that what im trying to understand I need to sumbit  a form and show the same state that the page was before sumbitting the form.
thats what im asking how to do it
I don't know what is happening when there is no action
Avatar of Nura111

ASKER

"You can use include redirect php functions to include another php site."- how do I do it in my exmple ? I dont understand it"
Avatar of Nura111

ASKER

No how do I psychically redirect it in  my exmple by using <INPUT TYPE=hidden URL="temp.php">??
what will cause it to go in temp.php if it not in the action og the form?
Try this
You will have in your let say current.html
<form action="process.php">

in process.php you can use

<?php include("current.php"); ?>
I want to said current.php not current.html
Avatar of Nura111

ASKER

I think we are taking on diffrent things.
if ill write inside of the code that is in main.php

if isset ($_POST['spamIt'])
{
include ("current.php");
}

so when sumbitiing the form it will process it in main.php and when it will get the include it will open current.php in the browzer??

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nura111

ASKER

I wrote it as a new question because it hink there was a misunderstood here I think the question is diffretn:

https://www.experts-exchange.com/questions/27323168/a-form-submit-action-and-handle-in-php.html
Avatar of Nura111

ASKER

Oh Hi RAY didnt see your response with the book is it also include the jquery and ajax issues I think my main problem now is that I dont fully understand the way a website/webapplication is commincate with the server and the diffrent between server side and client side scripting and  would this book help?

And I still kind of need to solve my current problem but I think I simplize it in the new question..
You have a lot of moving parts when you have a simple client-server application, like a web browser that talks to a server script by submitting a form.  When you add jQuery to the mix, it gets more complicated.

Here is how I usually try to build a web application.  First get the PHP script right.  Then add the HTML forms.  Then add the CSS to style the appearance of the HTML.  Then add the JavaScript or jQuery for the client-side presentation layer.  Others may see it differently, but that order of development works for me.

The problem that you and everyone else has when you start trying to build a site comes down to this.  There are complex interactions between PHP, MySQL, HTML, CSS, HTTP and JS.  You have to know all the technologies, and there are not any books that teach them all.  There are libraries and colleges, but they will teach you from several different books and courses.
Avatar of Nura111

ASKER

Yes you are right and believe it or not with my stupis question.. I have a computer science degree :)
but I wasn't dealing with those kind of technologies there ..

so Im trying to understand what are the foundation I Should learn first if you have recomandation for a specific certification or college class silibous about the area we have been recently discussed I will be happy to hear that.
and I will check the book you offered as well
If you have some background in computer science, the SitePoint book will serve you well.  It shows good examples and has good explanations of why we do certain things certain ways.

Almost any college level course in these topics will be helpful to you: PHP, MySQL, HTML, CSS, HTTP and JS.
Avatar of Nura111

ASKER

ok thank you
Avatar of Nura111

ASKER

all the comments help me but it wasnt really the soloution which is using jquery ti sumbit the form which I understoof later from diffrent questions I posted in EE
Thank you