Jump to content

Recommended Posts

I have two questions about processing a Form, question 1. I have a date drop down menu it has numbers in it, even though only numbers can be processed, should I still validate/check to make sure the value is a number before running my mysql Update query?

 

question 2. When the form is being processed and an invalid entry is found, how do I make the script redirect the user back to the form page? What's the professional way for doing this?

 

        $en = array_merge($en, $_POST['add']);
        $err = '';
        if ($en['user'] == '' || $en['pass'] == '' || $en['email'] == '') $err .= 'field is blank below<br>';

Link to comment
https://forums.phpfreaks.com/topic/128459-processing-form-question/
Share on other sites

1) Yes.  They don't have to use your form to send values to your site.

 

2) php: header('Location: yoursite.html');

  html: <meta http-equiv="refresh" content="0;URL=yoursite.html" />

  javascript: window.location = "yoursite.html";  (i think that's it..)

In addition to what xtopolis wrote, I would also store the post/get data in a session variable so when you go back to the form you can repopulate the form with the users previous entries so they don't have to enter it all over again.  Nothing bites more than taking time to fill out a form and forget one little thing only to have the form come up blank and have to re-enter all of the data.  Not user-friendly.

In addition to what xtopolis wrote, I would also store the post/get data in a session variable so when you go back to the form you can repopulate the form with the users previous entries so they don't have to enter it all over again.  Nothing bites more than taking time to fill out a form and forget one little thing only to have the form come up blank and have to re-enter all of the data.  Not user-friendly.

 

do you have an example of saving to a session and repopulating?

//assume the original post data contained [username="cronix"]
$_SESSION['formdata'] = $_POST;
//send user back to form
if(isset($_SESSION['formdata'))
{
    extract($_SESSION['formdata']);
    unset($_SESSION['formdata']);
} else {
    $username="";
}
//then in your form
<input name="username" value="<?php echo $username; ?>" />
//...

 

I didn't test it but it should be close

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.