- This topic is empty.
-
AuthorPosts
-
May 5, 2011 at 7:31 am #32609
Eamonn
MemberHi 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.
May 5, 2011 at 5:40 pm #47030ChrisBull
MemberYou 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.
May 5, 2011 at 5:44 pm #47031ChrisBull
MemberAlternatively – 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.
May 5, 2011 at 6:59 pm #47035Eamonn
MemberThanks 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 :)
May 6, 2011 at 8:23 am #46951ChrisBull
MemberSessions 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 . '';
May 7, 2011 at 4:43 am #46625Eamonn
MemberWell, 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?
May 7, 2011 at 8:28 am #46607ChrisBull
MemberWell, 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.May 7, 2011 at 2:27 pm #77296Eamonn
MemberBut the db will require a login/logout anyway (which I should have mentioned)… so couldn’t wrap it all up in that session?
May 8, 2011 at 7:39 am #77215ChrisBull
MemberI guess so, Just personal preference
May 10, 2011 at 5:50 am #76976udip
MemberYou may refer to this PHP form validation example.
May 12, 2011 at 7:05 am #76609Eamonn
MemberThx Udip
May 12, 2011 at 2:34 pm #76491fishnfrogs
Memberim 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
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.