Add HTML attr via PHP - php

First page has form using method POST with action to the offer page.
<form id="value-form" method="POST" action="/offer/">
When user submits form on the first page, I want on the offer page class="add-info" to be added to the <form so then it fires up the jQuery script
<form id="formOffer" class="add-info">
Jquery
if (formOffer.hasClass('add-info')) {
launchrocket();
}
I can't figure out class tag can be added via PHP to the new form on the process page.

Related

Form submit takes to Search page

Any idea why submitted form data loads the search.php page instead of submitting form?
URL: http://domain/contact-us/
On form submission it redirects to: http://domain/?s=&wpforms%5Bfields%5D%5B0%5D%5Bfirst%5D=iuiou&wpforms%5Bfields%5D%5B0%5D%5Blast%5D=uoiu&wpforms%5Bfields%5D%5B1%5D=amigoow%40yahoo.com&wpforms%5Bfields%5D%5B6%5D=General+Feedback&wpforms%5Bfields%5D%5B3%5D=7987&wpforms%5Bfields%5D%5B2%5D=ou&wpforms%5Bhp%5D=&wpforms%5Bid%5D=87632&wpforms%5Bnonce%5D=df749058ef&_wp_http_referer=%2Fcontact-us%2F&wpforms%5Bsubmit%5D=wpforms-submit
I have changed the plugin from ContactForm7 to WPForms but it turns out it's something not related to plugin.
Well your form opening tag looks like this:
<form method="get" action="http://newdev.propakistani.pk" role="search">
So its doing exactly as per this tag. You need to amend action to the URL of the php file that processes the form.

Ajax Refresh of Div on form submit oscommerce

In oscommerce I want to refresh the product div called 'left-div' with form field checked results on autosubmit- rather than whole page:-
I use oscommerce 2.3.4:-
Step wise I have below files-
I have pulled a form on index.php in a div called 'right-div',
which is called from a box module bm_form.php using below code-
if (class_exists(bm_form)) {
$boxdata = new bm_form;
echo $boxdata->getData();
}
Now this form has below code for action on bm_form.php:-
<form name="form_srch" id="form_srch" action="'.tep_href_link(FILENAME_DEFAULT).'" method="get" >.....</form>
The form is processed at this folder
ext/form/form.php
ext/form/form.js
ext/form/form.css
The above form process is called in my index.php using below code:-
at very top
require('includes/application_top.php');
require('ext/form/form.php');
The issue is I when I fill the form it triggers the entire page to refresh whereas I need to refresh only the div with form result.
My form.js uses below code for submit
$("#form_srch").submit(); // submit form
I tried using the idea given here for ajax refresh of Div-
Refreshing ajax div with form data
Editing this code in ext/form/form.js:-
$("#form_srch").submit(
function(e){
e.preventDefault();
$.get('ext/form/form.php', $(this).serialize(), function(data){
$('#left-div').html(data);
}
);
return false;
}); // submit form
And removed the action part from the form leaving action=""
But still it does not work at all the form stops working altogether,
Please can someone help me get this working......

How to return on the same page after submitting a form in php.?

I am making an e-commerce website where I have lots of products. If a user goes to any product items page and submits any form there then they should come on the same page.
So, how to come on the same page?
On the formular target page set:
header('Location: http://www.example.com/same_page');
Leave action attribute of form blank. Like so:
<form action="" method="post">
Or
<form action="#" method="post">
On your opening form tag add
action="submit.php"
then once it goes to that page when the submit button is hit add this
to the bottom of that php page:
header("Location: success.html OR success.php");
If you want to submit various forms on same page and then go back to the page where the form is submitted, you must also send the form URL of the page where it was sent, preferably in a hidden element. And after processing form redirect to URL stored in hidden.
You can use this :
header('Location: filename.php);
If you get any $_POST errors put it in a condition: if(isset[$_POST])
Thank You All. I Got My Answer
$_SERVER['REQUEST_URI']; will give the current URL with query strings.
Like my page is 'products.php?Product=20'
echo $_SERVER['REQUEST_URI']; =>/products.php?Product=20
So, we can directly use this in header location.

embedded php page after refresh (call self) filling out complete windows

i have an div (id="id_content") in Main.html, and an php file "cmp.php" is dynamically loaded by JQuery.load() in "id_content". It is working fine.
However after the "cmp.php" called itself (for updating) using following code : <form action="<?php echo $_SERVER['PHP_SELF']?>" target="_self" method="post" >
the "cmp.php" occupies the complete browser, what i want ist that "cmp.php" is always being displaye in div "id_content".
Thanks in advance.
The problem is that you are posting the form with the target="_self". This tells the browser that what is returned from the cmd.php should replace the content of the current window.
You have some options:
1) Create an iframe on the main.html like:
<iframe id="postframe"></iframe>
Change the the form to:
<form action="<?php echo $_SERVER['PHP_SELF']?>" target="postframe" method="post" >
The result of cmd.php will now appear inside the iframe when you submit.
2) Use Jquery to post/get your form data and handle the result in Javascript.
<form id="yourform">
</form>
$("#yourform").on("submit",function(e){
//Called when you hit submit
e.preventDefault(); //Don't post the form
//Create a request from form variables and send to server.
//Depending on the result alter id_content.
return false;
});
you can submit form by using Ajax

what is meant by action="#main_body" in a HTML form

I have form and some fields and I want send these fields to the next page via done.php using action="#main_body".
What are the differences between these two forms?
<form id="formElem" name="formElem" action="/ifs/form/index.php" method="post">
<form id="formElem " class="ifs" method="post" action="#main_body">
The complete action of the form is the URL of the page containing the form at the time of loading the form + the hashtag. So submitting the form will load the same page, but with a ahashtag (anchor) of #man_body. This is a side effect of action attributes being realtive if not definitly given as absolute.
Please be aware, that it is browser-dependant and header-dependant wether the page will actually reload or just scroll.
in the first case you send the values of your inputs to a specific page called done.php. In the second way you're calling the same page in which you have your form (plus an hashtag)
In the second link you are calling the same page with a hashtag of "main_body". it will work something like a 'TOP' link provided in lengthy pages which scrolled back to top of the page.
a difference is here the page will scroll(or reload) to "main_body" when you submit the form.

Categories