-1

I have a form, with some input elements (name, phone, address) like this:

<form  method="get" action="<!-- PHP --> echo htmlspecialchars($_SERVER['PHP_SELF']); <!-- ENDPHP -->" accept-charset="utf-8">

    <label>Nombre:</label>
<input name="nombre" id="nombre" type="text" placeholder="Tu nombre">
    <label>Teléfono:</label>
<input name="phone" id="tel" type="text" placeholder="666777666">
    <label>Dirección:</label>
<input name="address" id="direc" type="text" placeholder="Mi Casa">

                <fieldset>
                    <input value="Enviar" type="submit">
                </fieldset>
            </form>

After that form, there is a large php code to "post" the obtained data in phpbb (using submit_post() ) and formatting the body and title post.

Then when click on submit I want to validate form data (verifying that the phone is a number, for example) and, if all is ok, continue with the php script to post.

I have searched a bit, and found that is needed action="<!-- PHP --> echo htmlspecialchars($_SERVER['PHP_SELF']); <!-- ENDPHP -->" but when click on submit, page only reloads, without running the php code just below the form.

PD: this will be a html file to be used as template for phpbb3 so instead of <?php ... ?> is needed to use <!-- PHP --> .... <!-- ENDPHP -->

Any help or code is appreciated

minato
  • 9
  • 2
  • 1
    Is this your actual code `action="...` ? – Funk Forty Niner Jan 08 '14 at 17:42
  • 1
    You can simply use `action=""` if you want the form to submit to the same page that displayed it. But if you're having a problem with the code after the form, you need to show that to us. – Barmar Jan 08 '14 at 17:42
  • Previously I have called to another php file where the php code was, everything goes well, but now, I want to validate the content, and merge the two files in one putting the php code into the same php file as the form – minato Jan 08 '14 at 17:49
  • 1
    You can do as Barmar stated `action=""` and put your PHP on top, then your HTML under that, and using `exit;` after a successful submit, will prevent your form from showing up again, and only the posted values, if that is an option you want to use. @minato – Funk Forty Niner Jan 08 '14 at 17:51
  • Could you write me the skeleton of the code? I`m not sure what you said... sorry – minato Jan 08 '14 at 17:57

1 Answers1

0

Try this,

  • You need to enable PHP in templates in Security section of Admin Panel.
  • Make sure you refresh the template from Admin Panel and clear your browser cache after you've modified the code
Krish R
  • 22,583
  • 7
  • 50
  • 59
  • Previously I have called to another php file where the php code was, everything goes well, the problem isnt that, the problem is that putting the code of the other php file into the same file as the form, when click on submit, only reloads (changing the address that contains all the parameters) but no continues with the script, posting the form – minato Jan 08 '14 at 17:53