Jump to content
iNoize

How to get page ID if i send Form via post methode?

Recommended Posts

Hello, 

i use 3 different forms on site now i will check from which form the data comes and send the vars. 
e.g. I have a callback form, a contact form and an info form. 

Now i use one page Tnak you for your mail and how to choose the right script ? 
The forms have different number of values and i dont want to create 3 different Thank you pages. 

<?php
$empfang = "my@email.here";


if(isset($input->post->submit)) {

$aname       = $sanitizer->text($input->post->aktion_name);
$fname       = $sanitizer->text($input->post->fullname);
$subject     = $sanitizer->text($input->post->subject);
$femail      = $sanitizer->text($input->post->email);
$phone      = $sanitizer->text($input->post->phone);
$message     = $sanitizer->text($input->post->message);


$mail = wireMail();
$mail->to($empfang)->from($femail); 
$mail->subject('Anfrage von  '.$aname); 
$mail->body('Mail Body');
$mail->bodyHTML('<html><body><h1>von '.$fname.'</h1><br> Betreff: '.$subject.'<br> Mail'.$femail.'<br> Telefon'.$phone.'<br>Nachricht:'.$message.'</body></html>'); 
$mail->send(); 
}


 

 

Share this post


Link to post
Share on other sites

Why do you not include type hidden fields into your forms where you add identifiers?

$validFormIdentifier = ['aaaaaaaa', 'bbbbbbb', 'ccccccc'];
$myIdentifiedForm = $sanitizer->text($input->post->hiddenidentifier);
if(!in_array($myIdentifiedForm, $validFormIdentifier)) { 
	// invalid formsubmission, do not process further
}

 

  • Like 2

Share this post


Link to post
Share on other sites
On 6/11/2019 at 1:40 PM, horst said:

Why do you not include type hidden fields into your forms where you add identifiers?


$validFormIdentifier = ['aaaaaaaa', 'bbbbbbb', 'ccccccc'];
$myIdentifiedForm = $sanitizer->text($input->post->hiddenidentifier);
if(!in_array($myIdentifiedForm, $validFormIdentifier)) { 
	// invalid formsubmission, do not process further
}

 

Thanks for the advice but i need to know wchich form of my 3 forms is sending currently 
because form 1 has 5 values 
form 2 has 8 values and form 3 20 values to send. 

So i want to select what to send  it depends on the values 

Share this post


Link to post
Share on other sites

You have three forms on one page, so provide a hidden element with a unique name (as @horst suggests), then test for the form name when submitted and process accordingly.

The page with your forms...

<form>
  <input type="hidden" name="form1" value="form1" />
  ... // Your form data collection fields
</form>

...

<form> 
  <input type="hidden" name="form2" value="form2" />
  ... // Your form data collection fields
</form>

...

<form>
  <input type="hidden" name="form3" value="form3" />
  ... // Your form data collection fields
</form>

Then within your page, test for each...

<?php

if( $input->post->form1 == "form1" ) {

// process your data and send your message for option 1

} elseif ( $input->post->form2 == "form2" ) {

// process your data and send your message for option 2

} elseif ( $input->post->form3 == "form3" ) {

// process your data and send your message for option 3

}

// render your page as normal

 

  • Like 3

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...