2

I am facing the problem in WordPress. I passed the value from 1st page to 2nd page (here app-2) which shows the result (by using inspector) but when the form is submitted URL shows only

"app-2/?Screens=30"

But

"app-2/?type=app&Screens=30"

is meant to show. Why does this happen? Is it something to do with 'GET' method?

N.B: $_GET['type'] works perfectly.

<form action="app-2/?
type=<?php $type=$_GET['type']; echo $type;?>
&Screens=<?php echo $_POST['Screens'];?>" 
method="GET">

  <input type="radio" name="Screens" value="3 - 5" required/>
  <input type="radio" name="Screens" value="16 - 30" />

 <input type="submit" value="submit">
</form>
5
  • Is it a typo with form action: $_POST['Screens'] and you mean $_GET['Screens'] instead? Commented Jun 19, 2017 at 9:54
  • Maybe htaccess is rewriting the url. Commented Jun 19, 2017 at 9:55
  • @BenRoob No. He is using $_POST['Screens'] and appends it to the URL, so afterwards he can access it like $_GET['...']. It doesn't make too much sense though because he has a field with the name 'Screens' aswell that is required. Commented Jun 19, 2017 at 9:55
  • This form submit not possible. Commented Jun 19, 2017 at 9:56
  • actually, I used $_POST['Screens'] to get the form radio button value and used $_GET['type'] to get the previous URL parameter 'type' Commented Jun 19, 2017 at 10:07

2 Answers 2

1

$(".submit-form").submit(function(e){
   e.preventDefault;
   window.location.href = 'app-2/'+$(".submit-form").serialize();
   return false;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="" method="GET" class='submit-form'>
   
  <input type="hidden" name="type" value=<?php echo $_GET['type']; ?> 
  <input type="radio" name="Screens" value="3 - 5" required/>
  <input type="radio" name="Screens" value="16 - 30" />

 <input type="submit" value="submit">
</form>

You can try with javascript Please check answer it will helps you :)

Sign up to request clarification or add additional context in comments.

1 Comment

i just tried this example and it is working good.. url will be like xxxxxxxxxx/app-2/type=test&Screens=16+-+30
1

Try this one:

<?php
$parameters = "";
$parameters .= "?type=".(isset($_GET["type"])?$_GET["type"]:'')."&Screens=".isset($_GET["Screens"])?$_GET["Screens"]:'';

?>
<form action="app-2/<?=parameters?>" 
method="GET">

2 Comments

this is result for the above script?i'm pretty sure you are showing me some other result with your code.try the above one and show me the that url.
1st of all your code has syntax error then I try to resolve that and get that output. Here's the error of your code Error: There is 1 more closing curly braces '}' found. This count is unaware if curly braces are inside of a string. PHP Syntax Check: Parse error: syntax error, unexpected '<' in your code on line 3 $parameters .= "?type=".(isset($_GET["type"])?$_GET["type"]:'')."&Screens=".<?=isset($_GET["Screens"])?$_GET["Screens"]:''?>;} PHP Syntax Check: Errors parsing your code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.