Jump to content

When executing a function, the url changes to something totally awkward


senca99

Recommended Posts

Hey y'all!

 

I was writing a simple registrationform with some checks in it. I made a main registration page and a page with 3 functions ==> show_registration_form, process_registration_form and validate_registration_form.

The page displays well until I click on the submit button. For some reason, wether the input is correct or not, I get a 404 because you get linked to an unexisting link but I don't know why.

The regular url is this:

somethin.be/tweedekans/registreer.php but when submitting the url changes to this:

somethin.be/tweedekans/' . /tweedekans/registreer.php . '

with the magical allknown message: The requested URL /tweedekans/' . /tweedekans/registreer.php . ' was not found on this server.

The 2 files are both located in the same directory on the server.

 

Why is this happening? This is the code in the main page:

<?php

include("header.php");
include("functions_for_registration.php");

echo'<p>Registreer</p>';

if(isset($_POST['_submit_check'])) {
if($form_errors = validate_registration_form()) {
	show_registration_form($form_errors);
	}
	else {
		process_registration_form();
		}
}
else {
	show_registration_form();
	}


include("footer.php");

?>

 

And these are the functions:

 

<?php

function show_registration_form($errors = ''){
if(isset($_POST['_submit_check'])) {
	$defaults = $_POST;
	}

if($errors) {
	$error_text = '<tr><td>you need to correct the following errors:';
	$error_text .= '</td><td><ul><li>';
	$error_text .= implode('</li><li>', $errors);
	$error_text .= '</li></ul></td></tr>';
	}	
else {
	$error_text = '';
	}

/*
Initialisatie van de vars
*/
$voornaam="";
$familienaam="";
$straat="";
$huisnr="";
$postcode="";
$plaats="";
$mail="";
$telnr="";
$bijzonderheden="";

/*
De code voor het inschrijvingsformulier
*/
print<<<_HTML_
<form method="post" action="' . $_SERVER[php_SELF] . '">
<p>Vul je voornaam in: <br />
<input type="text" value="' .$voornaam. '" name="vnaam" />
</p>
<p>Vul je naam in: <br />
<input type="text" value="' .$familienaam. '" name="naam" />
</p>
<p>Straat: <br />
<input type="text" value="' .$straat. '" name="straat" />
</p>
<p>Huisnummer: <br />
<input type="text" value="' .$huisnr. '" name="huisnr" />
</p>
<p>Postcode: <br />
<input type="text" value="' .$postcode. '" name="postcode" />
</p>
<p>Stad: <br />
<input type="text" value="' .$plaats. '" name="plaats" />
</p>
<p>E-mail: <br />
<input type="text" value="' .$mail. '" name="mail" />
</p>
<p>TELnr(enkel cijfers!): <br />
<input type="text" value="' .$telnr. '" name="telnr" />
</p>
<p>Extra opmerkingen?: <br />
<input type="text" value="' .$bijzonderheden. '" name="bijzonderh" />
</p>
</p>
<input type="submit" value="Verzenden" /> <input type="reset" value="Wissen" />
</p>
</form>
_HTML_;
}


function validate_registration_form(){

$errors = array();

if(empty($POST['vnaam'])){
	$errors[] = 'U vergat een voornaam in te vullen';
	}
if(empty($POST['naam'])){
	$errors[] = 'U vergat een familienaam in te vullen';		
	}
if(empty($POST['straat'])){
	$errors[] = 'U vergat een straatnaam in te vullen';
	}
if(empty($POST['huisnr'])){
	$errors[] = 'U vergat een huisnummer in te vullen';
	}
if(empty($POST['plaats'])){
	$errors[] = 'U vergat een woonplaats in te vullen';		
	}	
if(empty($POST['mail'])){
	$errors[] = 'U vergat een e-mailadres in te vullen';
	}
if(empty($POST['telnr'])){
	$errors[] = 'U vergat een telefoonnummer in te vullen';
	}	

	return $errors;
}


function process_registration_form(){
print 'Dit formulier is geslaagd voor de test!';
}

?>

Because you are using a heredoc string to make your form, everything you put between the starting and ending <<<_HTML_ tags is part of that string. Don't use the dot . concatenation operator (the dots and any extra quotes become part of the string.)

 

Just put php variables directly inside a heredoc string without any concatenation.

Because you are using a heredoc string to make your form, everything you put between the starting and ending <<<_HTML_ tags is part of that string. Don't use the dot . concatenation operator (the dots and any extra quotes become part of the string.)

 

Just put php variables directly inside a heredoc string without any concatenation.

 

Sorry for the late reply, I wasn't tracking this thread by e-mail (which I thought I did).

Thank you for the help, I will try it!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.