Jump to content

redirecting to a form in another file


raydona

Recommended Posts

Hi,

I have a form in file A.php.

<?php

<form name="A.php" action="B.php" method="post">

......

<input type="text" name="name" id="name" />

....

<input type="text" name="email" id="email" />

....

?>

 

When the form is submitted php validation takes place on form B.php

<?php

if ( isset($_POST['submitted'])

{  if ($_POST[name])

  {  $name = $_POST[name]; 

    }

    else

  { //what code goes here?

  }

  ......

?>

What I would like to happen in the else statement is that if name field is left blank user is automatically redirected to A.php, the name field is highlighted and a small error message that the name field was left empty appears. How can that be achieved? I would be very grateful for all help.

Link to comment
Share on other sites

Is there a strong reason why you dont validate your form input on the same page? On A.php? 

for the action use "<?php echo $_SERVER["PHP_SELF"]; ?>" and include your isset validation in the top of your script.

 

This is just one way to do it.

 

algidDes702

Link to comment
Share on other sites

I would agree that processing/validation should be done above <html> on the same page however I would use a empty action line in the form, eg. <form action="" method="post">

 

I WOULD NOT USE $_SERVER["PHP_SELF"]

http://www.google.com/search?q=%24_SERVER%27PHP_SELF%27+xss+vulnerability&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a

Link to comment
Share on other sites

Hi,

  Many thanks for the replies.

  Although I didn't include all the code, there is a lot of javascript in A.php to make the form appear stylish instead of the standard HTML inputs. That is why I wanted to keep the file separate from the php validation.

  I was wondering if I could write <form action="" method="post"> in A.php and include("A.php"); in B.php immediately below the php validation so that A.php appears immediately below the validation in B.php. But then how would I jump to input label?

Link to comment
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.