Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

problems using get over mulitple files

Featured Replies

Hey all just wondering if anyone can help.

 

Basically I have a form that that has a php variable as the action.

 

<form class="indexSearch" action="<?php echo $indexSearchFormAction; ?>" method="get">

<ul class="indexSearchIndustryList">
<li>
<input type="checkbox" value="1" name="industryList[]"><a href="#">Bathroom Fitting</a>
</li>
<li>
<input type="checkbox" value="2" name="industryList[]"><a href="#">Bricklaying</a>
</li>
etc.....

 

To keep my code as neat as possible im putting all php functions and scripts in a seperate file that im including in the header of the page.

 

What im struggling with is on the page that handles all the php how do I target the array (industryList[])

 

what I have so far is

 

$indexSearchFormAction = "";
if (isset($_GET['indexSearchSubmit']))
{
if (!empty($_GET['industryList']))
{
$indexSearchFormAction = "search.php";
}
else
{
$indexSearchFormAction = "";
}
}
but im not sure if i need the $_GET
just a bit confused in general.
any help would be greatly appreciated.

 

 

  • 4 weeks later...

It looks like you want the form's action to be based upon whether the user has selected one of the checkboxes, is that right?

 

If so, you've got the process wrong in the PHP.

 

So let's say the page is loaded first time, form is empty, if statement is ignored, and the form's action value is empty. The user then selects a checkbox and hits submit. The page is loaded again, the GET parameters in the URL string, and this time the if statement runs, detects that the user has selected a checkbox, and so creates the variable $indexSearchFormAction and puts in the form's action value. However at this point, you are expecting the form to be submitted again - this time to search.php - if they selected something. For your code to work, they would have to again select the checkbox and hit submit.

 

You need to modify your code so that the action in your form is a static PHP file, regardless of what they enter, and then put all the logic in that file, and then work out what to do with the user.

 

However, I should point out that your PHP code is looking for the GET variable indexSearchSubmit to be in the URL string, but your code example doesn't appear to show this. Not sure if it's just not part of what you've pasted in, but you'd need to include it in a hidden form value. I would also recommend you use POST also, rather than GET, for a few different reasons.

 

Hope this helps.

You seem to be very confused, what your trying to do would be better done using ajax..

 

But if your not on ajax level yet (which im guessing your not, No offence) then i think that maybe you need to take a step back and look at the logic again

 

 

<form class="indexSearch" action="<?php echo $indexSearchFormAction; ?>" <----- This shouldn't be an empty variable when you first hit the page.

 

I.E this code personally makes no sense to me, unless i did something with ajax..

 

 

but heres what i would do

 

<form class="indexSearch" action="the_php_page.php" method="get">

 

Then on the the the_php_page.php i would have if conditions that handle different solutions

 

For example

 

if(checkbox one is select true){

 

do this

 

}else{

 

do something else

 

}

 

example two

 

if(isset($_GET[checkboxone])){

 

do this

 

}else{

 

do something else

 

}

 

 

 

But alternatively if you wanted a solution before they hit the first page, then look at sessions and cookies, but i wouldnt recommend this

You could also hide the form ie

 

 

the is the form page logic

 

<?php

 

if (!isset($_GET['something'])){

 

show checkbox (that will select form)

 

}else if($_GET['something'] == true){

 

show form one with the varible you need i.e

 

action is =search.php

 

}else if($_GET['something'] != true){

 

 

error or show form two etc...

 

}

 

?>

 

p.s research javascript onclick submit event, maybe that might help

Edited by sergRamalli

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.