GET variables in WordPress keeps going to 404 page - php

I'm using wordpress with a custom crm for a 2 part form.
When I send the first form data through from the form on the homepage it returns a customer ID in the URL to the second form page. However, the &recordid=xx makes wordpress returna 404 page.
How do I make the page not through a 404?
Original form second page: http://mysites.com/get-personalized-quote
Original form second page with variable: http://mysite.com/get-personalized-quote&recordid=2763

You should use ?recordid=2763 instead of &recordid=2763
note the ?

Related

Changing Redirect After Form Submittal

On my Wordpress website I have users fill out a form which ultimately generates a product. One of the form fields is a "Title" for the product. I'm trying to change the redirect for where the user is sent after they submit the form.
The URL for products are based on the "Title" of the product (e.g. http://example.com/product/My-Great-Product-Title/)
The issue with my current code is that I get a returned URL of... http://example.com/product/My%Great%Product%Title/
This returns a page not found 404 error.
Naturally a product title with no spaces in between the words works just fine but for obvious reasons every title can't be limited to one word.
My current code for redirecting which results with the 404 error...
$redirect = "http://example.com/product/$title";
How can I get my URL to be "My-Great-Product-Title" instead of "My%Great%Product%Title" which doesn't seem to work.
Assuming that the URL is generated by WordPress whenever the Product is created and now created by some other method you should be able to use sanitize_title() which is what WordPress uses to create their friendly permalinks.
The drawback to this is if there's a duplicate, it won't detect this but WordPress will append a -2 to the url. A better solution would be to get the ID after the product has been created and use get_permalink() which will be more accurate.

Redirecting php form to a bookmark on the referring page if there is a validation error

My php form mailer has this line of code that sends the user back to the form page if there was a validation error:
header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true");
It works fine, but the thing is that my form is at the bottom (footer) of the referring page. When there is an error, it simply goes back to the (top of the) referring page, but the user cannot see there was an error because it does not scroll down to the form.
I do have an HTML bookmark for that section, but I don't know how to add it to the code above so it will automatically scroll down to the form.
Is there anything I can add to the code above so it redirects down to that form part of the referring page, as in an anchored link like www.example.com#form?
Put the anchor before the query params i.e. example.com#errors?subject{$subject}&x=y

How to reload page containing POST data

I've got a section on every page of my site which allows the user to set a reminder. It loads the appropriate form on the page when the $addtracker variable is set in the url using:
$current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";?>
Add reminder
It works on every page except pages which rely on POST data, such as a search results page. When the link is clicked on these pages, the POST data disappears and so I get 0 results in the search and $_POST data not found errors.
How can I reload the current page with the POST data intact?
You should use form with method="GET"
Do not use link , use form with button.

How do I validate a form in CodeIgniter when my View only loads with a query string?

I've run into an issue validating my form as my View (the page where the form is) is loaded with a query string.
My view URL looks like: http://mydomain.com/insert/new?image=http://www.image.com/image.jpg
For this view to work, I need the query string as it looks up the image URL and performs an action on my page.
When I submit a form on this page that wasn't validated (validation works fine), instead of using $this->load->view('insert_new'); (where insert_new is my view page with the URL above), I construct a URL dynamically with the query strings and use the header('Location:' . $view); function. The view file has echo form_errors(); in it but, I don't see any errors. Is this because of the constructed URL and query string? To also confirm, my controller functions to view the page and handle the form are different. How do I get this to work? Thanks.
If I understand correctly your flow is as follows:
System loads form page with GET url data (image)
User submits form
System validates form and redirects to to $view using a HTTP redirect
The problem is, that by redirecting the POSTed form data is lost, because the browser sends another GET-Request to the constructed URL - and does not re-submit the data!
So if you want to show any form errors you must do that in the same request as the validation, ie by loading a view after the validation instead of redirecting.

Stay on current page after POST

I have a form which once the Submit button is pressed, it goes to a blank page and returns any error messages on that blank page. However I have a website template and I wish that my script is run, and returns the the page which did the action POST and puts any error messages on that page.
Example of what is happening:
PAGE REQUESTS POST ----> SCRIPT RUNS ---> RETURNS ERROR MESSAGE
What I want it to do is:
PAGE REQUESTS POST ---> SCRIPT RUNS ----> GOES TO THE PAGE WHICH REQUESTED POST ----> SHOWS ANY ERROR MESSAGES WHICH THE SCRIPT PICKED OUT.
Sure you can, just set the Action of your form to the current page. Then the $_POST will contain all the values the user filled in the form.
You have two options. I assume your are going to a blank page, because your POST goes to a PHP script different from the page it is posting from.
Option 1 - Post to the same PHP page as the page your are posting from.
Option 2 - Once you have posted, and generate an error, redirect back to the page, with the errors stored in a session, or a cookie, so that they can be rendered on the original page.
Assuming that the page containing the request form is also able to display the error messages, set the form attribute to the url of the page containing the form (as TJHeuvel noted) or just make action attribute empty, e.g, <form action="">.
After going to blank page store all the posted variables in your variable say $get with syntax param1=value1&param2=value2 and so on...and redirect back by header("Location: back.php?$get"); and in your main page by $_GET echo all the vars

Categories