- This topic is empty.
-
AuthorPosts
-
March 25, 2015 at 11:07 am #198979ThadleyParticipant
For my personal website, I am trying to learn a bit more about forms and PHP validations rather than use a plugin. It’s a simple form with a $fullname, $email, $subject, $website, $message and a normal submit button.
I linked a codepen just to show you my PHP and HTML. I couldn’t get them to show up in here for some reason.
I have read that leaving the action=”” attribute empty will basically just refresh the page whenever the form is submitted. My website is simply one page so I don’t really need it to redirect me to another page.
The PHP that checks if the fields are empty work because it revealed the appropriate message, although for obvious reasons, having them display before the user attempts to submit anything is pointless.
I’m not sure if the IF statement surrounding the empty IF statements is right but either way when I click submit button, it refreshes the page and its now an empty blank white page with no HTML. The URL localhost:8888/wordpress stayed the same though except its a blank page.
This is really annoying me and no matter what I try I get the same result. Any ideas what I’m doing wrong and is this a specific wordpress issue?
March 25, 2015 at 11:12 am #198982Paulie_DMemberThere’s obviously something in your content that the forum doesn’t like.
Try making sure that any commands or code or whatever are wrapped in backticks like the example right below this box where it says “Posting Code”
<script> function example() { element.innerHTML = "<div>code</div>"; } </script>
Please don’t keep starting new threads when whatever you are doing isn’t taking effect properly.
March 25, 2015 at 11:17 am #198984SenffParticipantIn wp-config.php, change this line:
define('WP_DEBUG', false);
To this:
define('WP_DEBUG', true);
Try again and see if there are any PHP errors now that may give you some clues.
March 25, 2015 at 8:47 pm #198999ThadleyParticipant@Senff It is already on and it isn’t showing any errors that makes sense. The only errors are regarding the variable that contains the hidden submitted input below. :s
$_POST['submitted'];
@Paulie_D Well considering the new thread is about a different issue, I would see this as being a good idea. Why would I keep posting in a CSS thread I created for example when its a PHP problem and a completely different problem?March 27, 2015 at 12:16 pm #199163ThadleyParticipantI figured it out. In the reading section of wordpress, I set it to use a page for my front page instead of having it set to “your latest posts” only because I don’t have a blog yet.
I had all my code inside the page.php file instead of the index.php file so whenever I hit submit, it would refresh and essentially load the blank index page. I just transferred all my code into the index file, adjusted my file paths and put it back to “your latest posts” so that it would read the index file and it worked. Everything is good for now :) I just thought I would update my thread.
March 27, 2015 at 1:26 pm #199165AlenParticipant@Thadley, you can look at the Template Hierarchy on Codex. It’s a great guide to how WP templating works. You can also create your own custom templates, which is a great way to handle multiple variations of page templates. Hope that’s helpful. Alen.
April 5, 2015 at 9:41 pm #199811Sagive SEOParticipantsince your using WordPress i would skip the whole refresh page to submit a form and use ajax…
That makes the whole error checking simpler and also helps you avoid the refresh which is just 1990.
Here is the HTML code: http://pastebin.com/iwe8WESv
Here is JS code: http://pastebin.com/vYzAy0kA
Here is the PHP code: http://pastebin.com/AShhpZekPlace JS & PHP file in a folder named “ajax” in your theme folder, include the PHP file in your functions.php file and your done.
Best of luck ;)
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.