Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Returning form validation msg from an action script without Javascript

  • This topic is empty.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #32609
    Eamonn
    Member

    Hi guys,

    I have a form page, and an action page to proccess said form via php. The form works fine, and I’ve got to the stage where it will accept edits, new entries, deletes, strip duplicate entries, funny chars, etc, and redirect back to the original form no probs.

    The current incarnation however checks for duplicate entries, and echoes out an error msg if one is found on a blank screen. Not pretty:

    	elseif (($_POST) == ('areacode-insert')) {
    $newname = $_POST;

    $trimmed = trim($newname, " :;'#()<>/-.");

    $result = mysql_query("SELECT * FROM prm_contactareacode WHERE ContactAreaCode='$trimmed'");
    if (mysql_num_rows($result) == 0)
    {
    $query="INSERT INTO prm_contactareacode SET ContactAreaCode='$trimmed'";
    mysql_query( $query) ;
    header ("location:modify-areacode-list.php");
    }
    elseif (mysql_num_rows($result) > 0)
    {
    echo 'This value has already been submitted!';
    }
    }

    I’m wondering if it is possible to return a form validation msg (e.g. “This value has already been submitted”, or “No value was entered”, etc.) from that action script back to the form page without using ajax/javascript. Every Google result tells me ‘Sure!, but here’s how to do it using Ajax….’ :(

    Any help would be great – I’ll post the entire code if required.

    #47030
    ChrisBull
    Member

    You should have the form and the validation code on the same page. I helped someone with something like this the other day, try and integrate your code with this posts (the final version is my second to last post). Reply back if you still need help.

    #47031
    ChrisBull
    Member

    Alternatively – You said that the current thing you have already redirects back to the original form, why not chuck in a global get variable in the url, ie http://www.site.com/form.php?q=1 then check what the variable is and display appropriate message. Although i don’t advise this method, has many limitations compared to the method i mentioned earlier.

    #47035
    Eamonn
    Member

    Thanks for that Chris,

    I was looking at the post-to-self method, but was wondering if there was an alternative, two-page method other than the GET query. Possibly a SESSION or somesuch…

    I’ll probably go with the one-page method in the end :)

    #46951
    ChrisBull
    Member

    Sessions would work but i still don’t think they would be the best way forwards. However if you were to use it then in the validation .php you could find an error and do,


    $_SESSION = "invalid format";

    and then after the redirect to the form .php you can have something like,


    ' . $_SESSION . '';
    #46625
    Eamonn
    Member

    Well, I was just thinking of (on error) giving a variable a value, and then echoing that value on the form page after the redirect – would that work? Why do you think sessions are not the best way forward?

    #46607
    ChrisBull
    Member

    Well, I was just thinking of (on error) giving a variable a value, and then echoing that value on the form page after the redirect

    That would be done using the code it posted.
    Using sessions just seems a long winded way to get something simple done. They lack the flexibility that having a 1 page form and validation would have. You would also have to clear the sessions after each form submission. Also from a small point, the more page requests the site is making will slow it down.

    #77296
    Eamonn
    Member

    But the db will require a login/logout anyway (which I should have mentioned)… so couldn’t wrap it all up in that session?

    #77215
    ChrisBull
    Member

    I guess so, Just personal preference

    #76976
    udip
    Member

    You may refer to this PHP form validation example.

    #76609
    Eamonn
    Member

    Thx Udip

    #76491
    fishnfrogs
    Member

    im probably confused here…but why not just use a URLLoader in actionscript…POST the variables to the php that processes the form…then echo the message back to actionscript so the user never leaves the page where the actionscript takes place…you can redirect the page after that or handle any other work from there…but this might not be what youre looking for…i get lost easily

Viewing 12 posts - 1 through 12 (of 12 total)
  • The forum ‘Back End’ is closed to new topics and replies.