JamesWinfield Posted August 29, 2016 Share Posted August 29, 2016 Hello I have just started to learn PHP, via some courses on Lynda, and am trying to amalgamate what I've learnt into a contact form on a half-finished website. I am not actually entirely sure if it is actually a PHP problem, but given that is where my knowledge is weakest, that is my best guess. If you click "Contact Us" on www.ineedaweatherforecast.co.uk, then click "send your message" without inputting any data, it goes back to the main page. Then if you click "Contact Us" again, you will see the relevant warnings are displayed. I have also split out the most basic part of the form onto a separate page where it seems to be behaving as suspected - www.ineedaweatherforecast.co.uk/test.php. Can anyone kindly advise me why it is going back to the home page instead of staying on the "Contact Us" section and bringing up the error? Thanks James Quote Link to comment https://forums.phpfreaks.com/topic/302032-beginners-problem/ Share on other sites More sharing options...
Jacques1 Posted August 29, 2016 Share Posted August 29, 2016 Both forms do exactly the same: The data is submitted to the action URL, which causes that page to be loaded. The problem of your main site is that your navigation is implemented purely with JavaScript. When the target page is loaded, this also resets the JavaScript state. There are two options to fix this: Instead of using classical form submission, you submit the data with Ajax. You change the URL with JavaScript whenever you switch to a different page (via the History API) and make the pages directly accessible through those URLs. For example, the contact page would get the URL /index.php?page=contact. Then you can jump to one specific page in your form. The first one is propably what you want. Quote Link to comment https://forums.phpfreaks.com/topic/302032-beginners-problem/#findComment-1536811 Share on other sites More sharing options...
JamesWinfield Posted August 29, 2016 Author Share Posted August 29, 2016 Thanks for your advice. Guess I will need to do a course on Ajax too then! Quote Link to comment https://forums.phpfreaks.com/topic/302032-beginners-problem/#findComment-1536813 Share on other sites More sharing options...
Michael_Baxter Posted August 29, 2016 Share Posted August 29, 2016 $errors = array(); // perform validations on the form data $required_fields = array('menu_name', 'position', 'visible', 'content'); $errors = array_merge($errors, check_required_fields($required_fields, $_POST)); just to check that you have set up your errors array properly into your field validation something like: and your form functions.php Quote Link to comment https://forums.phpfreaks.com/topic/302032-beginners-problem/#findComment-1536846 Share on other sites More sharing options...
Jacques1 Posted August 29, 2016 Share Posted August 29, 2016 Is this a question? A statement? Quote Link to comment https://forums.phpfreaks.com/topic/302032-beginners-problem/#findComment-1536847 Share on other sites More sharing options...
Michael_Baxter Posted August 29, 2016 Share Posted August 29, 2016 mine was more a statement as I have used some of Lynda tutorials Quote Link to comment https://forums.phpfreaks.com/topic/302032-beginners-problem/#findComment-1536848 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.