PHP send part of form under a certain condition - php

I have a search form through which users can, well, perform searches. When the "advanced search" checkbox is checked, a new part of the form shows, allowing for full customisation of the search. For a multitude of reasons, I have decided to send the form using the "get" method, thus displaying all variables in the url.
Problem is, when submitting a non-advanced search, the variables from the advanced part are still sent using the get method, making for a lengthy URL when it is not needed, as the advanced variables aren't used by the PHP that handles the search.
To hide the advanced form when the "advanced search" checkbox isn't checked, I've put the advanced form in a div of its own and have JavaScript set its style.display to "none" when the checkbox isn't checked, and have it reset to default when it is.
How would I best go about submitting only part of the form when "advanced search" isn't checked? A form within a form, removing and re-writing the div's content instead of simply hiding it, or what? Or is there an easy trick to this nobody's told me about?
Thanks!

you should probably use the attribute
<input disabled="disabled" ..
on the input fields when you do not want to submit them
you can find more information in this article
you will probably need to keep your "display:none" as the rendering of disabled elements depends on the browser.

If you take the part where you do the display:none and add a piece where you set all the form-fields to disabled you'll be set.

You could probably use two forms, one for a simple search and one for an advanced search.
If the 'advanced' search is selected, hide the simple search and vice-versa.

Hi I think you use a Ajax (Jquery) part and load the Advance part. So from the server side you easily retreive. If you post your code part we can give a clear answer. thank you

Related

Pass data to other website search

Is there a way to search on www.qantas.com.au or other sites that don't use GET method, from my own form?
I mean something like this : http://site.com/search.php?data=myData
I don't want to return result on my webpage, I just want to send data with a href
Depending on the website, many forms may contain CSRF tokens intended to prevent this behavior (imagine if a third party site could 'submit' a form for you to another site, perhaps to trans fer money or write embarassing posts)
That said, for sites that don't implement this feature, it should be possible just to copy their form (from <form> to </form>) including the action="/their/website/controller" and method="POST" (if you want it posted)
If you want to design your own form that submits the same data, just make sure the input fields have a name="blah" the same as the form data value that you want to submit
AJAX is also an option if you dont want to use a form. (see http://api.jquery.com/jQuery.post/)

HTML form within another form

I am new to html, I would be really glad if you can help me with this.
I have a web page where there is a list and some other text inputs and buttons. This option list can be populated by clicking the "add" button in the page, this add button is to direct to another page and in that page there are some chekboxes, those which are checked are loaded back to the main page,(where I have the list) .
At the end data in the main page needs to be loaded to the database, (what is in the list and in the text inputs).
Since I'm new I just know little about php and html, I thought I should have a form within a another form(form to "add items", form to load to the database) and it is not possible in html. Can anyone suggest the best way to do this? Do I need to use javascript?
Why can't the extra inputs (the ones that would be in the second form) be part of the first form? I think the question will become clearer if you post a sample form so we can see the relationship between the two forms.
But overall, since you're ultimately only submitting one form, then maybe all the inputs belong together. If what you're calling the second form isn't supposed to be visible right away, you can still have it be part of the same form, but only reveal it when needed.
Again, some sample data would help to understand the exact context of your question.
in php if you use input name="somename[]"
for a number of input elems
you will get an array in $_POST['somename'] and access all the values.
I think what you're after - if I understand you correctly - is ajax. Ajax allows you to asynchronously send data to/from another script without leaving the current page. This is accomplished using JavaScript. In your case I think what you need to do is set an onclick event in JavaScript to a button:
<input type="button" onclick="javascriptFunction()">
You can read more about ajax here:
http://www.tizag.com/ajaxTutorial/ajaxform.php

How to Create PHP Form with Collapsible Sections?

I have a multi-part form that will use PHP for the server side database insertion. The form needs to be validated, and I intend to use JQuery Validate to display one icon if the section validates, and another if the section does not.
I'm aware of the use of collapsible panels or DIVs. However, I need to use this same collapsible effect inside my form. How can this be achieved either via JQuery or another client side library?
Thanks much!!
Since you're at the point to decide what framework to use you may check the collapsible forms by ExtJS framework, it may give you some initial idea.
EDIT
#SidC: OK, if you're going with JQuery, you'll better not to mess up with Ext. Don't see much pain to implement if from zero using JQuery::Accordion plugin plus the JQuery::DIALOG. And check this feed
JQuery Accordion: how to embedded it into a dialog box?
You can hide inside a form just as easily as outside.
object.style.display = "none"
is the JS.
Wrap what you're showing and hiding in a div and go to it.
Scott is correct, and not only because we share the same name.
Wrap your HTML form in a div, and then use this:
http://www.dynamicdrive.com/dynamicindex17/animatedcollapse.htm
It's animated too ;)

Multi page ordering form php or ajax

I'm looking to create a multi page ordering form the first page would contain some dropdown and text fields, the second page would contain more text fields, the third page would be an order summery with paypal payment option.
I'm just wondering what the best way to create this order form is. I've used sessions in the past but never with users entering in text and picking items from drop downs, does anyone have any resources for doing this? Or does anyone know of a jquery or other ajax example or plugin I might be able to use and modify.
any insight would be a big help.
thanks
The simplest technique might be to use hidden form fields to carry fields from previous screens through to the final screen.
Just make sure you validate all the values when the final screen is submitted to make sure that the user hasn't twiddled the data.
You don't need to do pagination at all if you don't won't to. Just use css to show/hide the "pages". It doesn't sound like you have to save the "state" at any point.
But if you want to do multiple pages, use a session or a cookie to track the user. Then save the data to a database a mark it as incomplete. On the final page, retrieve it all and show it on the page. The server can't tell if a request is ajax or not, so it doesn't matter what you use for submission.

Pagination and $_POST

I want to do a search with pagination, but I don't know how to 'store' the data in the $_POST array, should I do it with sessions?
Rolensen
If you are doing a search, you are trying to GET data from the server, and not send data to it -- which means you probably should use GET, and not POST.
Also, it would allow your users to bookmark the result pages (or send those links by e-mail, IM, ...), which is always nice ; and, also, use the back/forward buttons of the browser without getting an alert box, which is nice too ^^
(Oh, and, BTW, it would help solve your problem ;-) )
Yes, you can use sessions or hidden fields and even better GET method in your form.
It is possible to use both GET and POST in form, just add appropriate attribute method to form tag:
<form action="index.php?page=5" method="POST">
So the pager links are submit buttons while rest of the data is stored in hidden fields. But that's not a good way to do this because you cannot pass someone link (on IM for example) to your search results.
But the best way is to store somewhere POST input data (look here: http://www.symfony-project.org/plugins/, when you input your query once, it is stored and remembered so you dont need to fill form multiple times)

Categories