Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/302032-beginners-problem/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/302032-beginners-problem/#findComment-1536811
Share on other sites

$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

Link to comment
https://forums.phpfreaks.com/topic/302032-beginners-problem/#findComment-1536846
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.