WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Form action="" (3 posts)

  1. Andrew
    Forum Moderator
    Posted 2 years ago #

    Hi,

    I'm trying to use my own form I've hand-coded, with HTML and PHP.
    When I submit the form (front-end), I am redirected to a page showing:

    Nothing Found
    Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.

    This is my code

    $form = true;
    
    					if ($_POST['submit']){
    						$errors = checkFields($_POST);
    
    						if($errors){
    							$error_content = '
    							<div class="errors">
    								<ul>';
    							foreach($errors as $error){
    								$error_content .= '<li>' . $error . '</li>';
    							}
    							$error_content .= '
    								</ul>
    							</div>';
    						}
    						else{
    							$to = 'emailaddress';
    							$from = "noreply@joetremlindesigns.co.uk";
    							$subject = $_POST['name'].' has contacted you';
    							$headers = 'From: ' .$from . "\r\n";
    							$headers .= 'MIME-Version: 1.0' . "\n";
    							$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    
    							$message =
    							'<table>
    								<tr>
    									<td width="300px">
    										<table><tr><td width="100px">&nbsp;</td></tr></table>
    									</td>
    									<td>
    										<img src="http://www.andrewnevins.co.uk/joe-tremlin-designs/images/full-logo.png" style="display: block; float: left; margin-left: 50px;" alt="Joe Tremlin Designs" />
    									</td>
    								</tr>
    								<tr>
    									<td width="300px">
    										&nbsp;
    									</td>
    									<td>
    										<a href="www.joetremlindesigns.co.uk" style="color: #E61B72; font-weight: bold; font-size: 13px; font-family: verdana, arial, sans-serif; text-decoration: none !important;">
    											www.joetremlindesigns.co.uk
    										</a>
    									</td>
    								</tr>
    							</table>'.
    
    							'<p style="color: #666; font-weight: lighter; font-size: 13px; font-family: verdana, arial, sans-serif;">'.
    							'<span style="font-family: verdana, arial, sans-serif; font-weight: bold">'.$_POST['name']. '</span>' .
    							' has filled out your Contact form.</p>'
    
    							.
    
    							'<p style="font-size: 14px; color: #1D70B7; font-weight: bold;"> Details: </p>'.
    							'<p style="font-size: 12px"><span style="font-family: verdana, arial, sans-serif; font-weight: bold">Name: </span><span style="font-family: verdana, arial, sans-serif; ">' . $_POST['name'].  '</span><br />' .
    							'<span style="font-family: verdana, arial, sans-serif; font-weight: bold">Email: </span><span style="font-family: verdana, arial, sans-serif; ">' . $_POST['email'].  '</span><br />' .
    							'<span style="font-family: verdana, arial, sans-serif; font-weight: bold">Message: </span><span style="font-family: verdana, arial, sans-serif; ">' . $_POST['message'] . '</span></p>' ;
    
    							$form = false;
    							mail($to, $subject, $message, $headers);
    						}
    					}
    
    					if ($form){
    					?>
    						<p>
    							Or email me using this form:<br />
    							<span class="bold">All fields required.</span>
    						</p>
    						<?php echo $error_content; ?>
    						<div class="form clearfix">
    							<form action="" method="post">
    								<label for="name">Name</label>
    								<div>
    									<input required="required" type="text" value="<?php echo $_POST['name'] ?>" name="name" autofocus="autofocus"/>
    								</div>
    
    								<label for="email">Email Address</label>
    								<div>
    									<input required="required" type="text" value="<?php echo $_POST['email'] ?>" name="email"/>
    								</div>
    
    								<label for="message">Message</label>
    								<div>
    									<textarea required="required" rows="5" name="message"><?php echo $_POST['message'] ?></textarea>
    								</div>
    								<input type="submit" name="submit" value="send" class="submit" />
    							</form>
    						</div>
    
    					<?php
    						}
    						else{
    					?>
    						<p>
    							<span class="green bold">Thank you</span>&nbsp;<span class="green"><?php echo $_POST['name'] ?></span>&nbsp;for taking the time to contact me.</p>
    							<p>I will try to get back to you through your email <span class="green"><?php echo $_POST['email'] ?></span>&nbsp;as soon as possible.
    						</p>
    					<?php
    						}
    					?>

    Any idea why I can't redirect to the same page?

  2. Andrew
    Forum Moderator
    Posted 2 years ago #

    SOLVED
    Followed this
    http://www.cabeeb.com/2009/09/posting-a-form-to-a-wordpress-page/

    "So the moral of the story is this:
    If you are posting a custom form anywhere within WordPress, use very unique field names so that they don’t conflict with WordPress’ variables. Otherwise, when you submit the form, it will have errors displaying the page, and instead display the 404 error page."

  3. peter.grafico
    Member
    Posted 1 year ago #

    thanks for the solution Andrew, that helped me out.i didn't realise that i had 2 forms with the same input names on my site.

Topic Closed

This topic has been closed to new replies.

About this Topic